@@ -3538,13 +3538,17 @@ reduces them without incurring seq initialization"
3538
3538
(aset a i init-val-or-seq))
3539
3539
a)))))
3540
3540
3541
- (defn- bounded-count [s n]
3542
- (if (counted? s)
3543
- (count s)
3544
- (loop [s s i n sum 0 ]
3545
- (if (and (pos? i) (seq s))
3546
- (recur (next s) (dec i) (inc sum))
3547
- sum))))
3541
+ (defn bounded-count
3542
+ " If coll is counted? returns its count, else will count at most the first n
3543
+ elements of coll using its seq"
3544
+ {:added " 1.9" }
3545
+ [n coll]
3546
+ (if (counted? coll)
3547
+ (count coll)
3548
+ (loop [i 0 s (seq coll)]
3549
+ (if (and (not (nil? s)) (< i n))
3550
+ (recur (inc i) (next s))
3551
+ i))))
3548
3552
3549
3553
(defn spread
3550
3554
[arglist]
@@ -3668,7 +3672,7 @@ reduces them without incurring seq initialization"
3668
3672
([f args]
3669
3673
(let [fixed-arity (.-cljs$lang$maxFixedArity f)]
3670
3674
(if (.-cljs$lang$applyTo f)
3671
- (let [bc (bounded-count args (inc fixed-arity))]
3675
+ (let [bc (bounded-count (inc fixed-arity) args )]
3672
3676
(if (<= bc fixed-arity)
3673
3677
(apply-to f bc args)
3674
3678
(.cljs$lang$applyTo f args)))
@@ -3677,7 +3681,7 @@ reduces them without incurring seq initialization"
3677
3681
(let [arglist (list* x args)
3678
3682
fixed-arity (.-cljs$lang$maxFixedArity f)]
3679
3683
(if (.-cljs$lang$applyTo f)
3680
- (let [bc (bounded-count arglist (inc fixed-arity))]
3684
+ (let [bc (bounded-count (inc fixed-arity) arglist )]
3681
3685
(if (<= bc fixed-arity)
3682
3686
(apply-to f bc arglist)
3683
3687
(.cljs$lang$applyTo f arglist)))
@@ -3686,7 +3690,7 @@ reduces them without incurring seq initialization"
3686
3690
(let [arglist (list* x y args)
3687
3691
fixed-arity (.-cljs$lang$maxFixedArity f)]
3688
3692
(if (.-cljs$lang$applyTo f)
3689
- (let [bc (bounded-count arglist (inc fixed-arity))]
3693
+ (let [bc (bounded-count (inc fixed-arity) arglist )]
3690
3694
(if (<= bc fixed-arity)
3691
3695
(apply-to f bc arglist)
3692
3696
(.cljs$lang$applyTo f arglist)))
@@ -3695,7 +3699,7 @@ reduces them without incurring seq initialization"
3695
3699
(let [arglist (list* x y z args)
3696
3700
fixed-arity (.-cljs$lang$maxFixedArity f)]
3697
3701
(if (.-cljs$lang$applyTo f)
3698
- (let [bc (bounded-count arglist (inc fixed-arity))]
3702
+ (let [bc (bounded-count (inc fixed-arity) arglist )]
3699
3703
(if (<= bc fixed-arity)
3700
3704
(apply-to f bc arglist)
3701
3705
(.cljs$lang$applyTo f arglist)))
@@ -3704,7 +3708,7 @@ reduces them without incurring seq initialization"
3704
3708
(let [arglist (cons a (cons b (cons c (cons d (spread args)))))
3705
3709
fixed-arity (.-cljs$lang$maxFixedArity f)]
3706
3710
(if (.-cljs$lang$applyTo f)
3707
- (let [bc (bounded-count arglist (inc fixed-arity))]
3711
+ (let [bc (bounded-count (inc fixed-arity) arglist )]
3708
3712
(if (<= bc fixed-arity)
3709
3713
(apply-to f bc arglist)
3710
3714
(.cljs$lang$applyTo f arglist)))
0 commit comments