(->> (iterate dec 10) (take 20) (map #(/ 6 %)) (seque 5) (last))
3
(apply (fn [a b & r] [a b (take 3 r)]) (iterate inc 0))
[0 1 (2 3 4)]
(mapcat #(rest (reductions conj [] %)) (take-while seq (iterate rest [1 2 3 4])))
([1] [1 2] [1 2 3] [1 2 3 4] [2] [2 3] [2 3 4] [3] [3 4] [4])
(apply str (concat (range 10) (take 26 (map char (iterate inc (int \a))))))
"0123456789abcdefghijklmnopqrstuvwxyz"
(macroexpand '(->> (iterate scratch.core/cuts [1 2 3 4]) (map count) (take-while pos?)))
(take-while pos? (map count (iterate scratch.core/cuts [1 2 3 4])))
((fn [aseq] (let [foo (nth aseq 1000000) bar 5] foo)) (iterate inc 1))
1000001
(let [s (iterate inc 0)] (print (take 2 s)) (print (take 2 s)))
nil
"(0 1)(0 1)"
(first (nth (iterate (fn [[a b]] [b (+ a b)]) [0 1]) 6))
8
((fn [x] (mod x (nth (iterate #(* 2 %) 1) 16))) 18761459871)
10399
(butlast (map (partial take 2) (take-while seq (iterate rest [1 2 10 11]))))
((1 2) (2 10) (10 11))
(map #(conj %2 %1) (iterate inc 0) (partition 2 1 [:end] "test"))
((0 \t \e) (1 \e \s) (2 \s \t) (3 \t :end))
(first (filter #(not (contains? {1 :a, 2 :b} %)) (iterate inc 1)))
3
(let [*modulus* 3] (take 3 (iterate #(-> % (inc) (mod *modulus*)) 1)))
(1 2 0)
(apply (fn [x y z & args] [x y z]) (iterate inc 0))
[0 1 2]
(let [coll (take 10 (iterate inc 1))] (/ (apply + coll) (count coll)))
11/2
(let [[hd & tl] (map #(doto % prn) (iterate inc 1))] hd)
1
"1\n2\n"
(for [[i x] (map vector [:foo :bar :baz] (iterate inc 0))] [i x])
([:foo 0] [:bar 1] [:baz 2])
(take 10 (apply concat (iterate (fn [x] (concat x (butlast x))) [1 0])))
(1 0 1 0 1 1 0 1 1 0)
(take 10 (map #(/ (* % (inc %)) 2) (iterate inc 0)))
(0 1 3 6 10 15 21 28 36 45)
(let [[a b & rest] (iterate inc 0)] [a b (take 3 rest)])
[0 1 (2 3 4)]
(take 10 (map first (iterate (fn [[a b]] [b (+ a b)]) [1 1])))
(1 1 2 3 5 8 13 21 34 55)
(-> (for [x (take 100 (iterate inc 0))] (do (println x) x)) seq boolean)
true
"0\n"
(take 5 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3)
(take 39 (map second (iterate (fn [[x y]] [y (+ x y)]) [0 1])))
(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986)
(take 10 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3 5 8 13 21 34)
(nth (iterate rest [1 2 3 4 5 6 6 7 8 9]) 3)
(4 5 6 6 7 8 9)
(take (count [1 2 3 4 5]) (iterate rest [1 2 3 4 5]))
([1 2 3 4 5] (2 3 4 5) (3 4 5) (4 5) (5))
(for [[x n] (map vector [:a :b :c] (iterate inc 0))] (println x n))
(nil nil nil)
":a 0\n:b 1\n:c 2\n"
(def triangle-nums (map #(/ (* % (+ % 1)) 2) (iterate inc 1)))
#'user/triangle-nums
(take 10 (map first (iterate (fn [[a b]] [b (+ a b)]) [1 2])))
(1 2 3 5 8 13 21 34 55 89)
((fn [n] (first (nth (iterate (juxt second (partial apply +)) [1 1]) n))) 6)
13
(->> (map (juxt first rest next) [() [] #{} {} nil]) (apply =) (iterate true?) (take 3))
(true true true)
(let [v [1 2 3]] (= (take (count v) (iterate inc (first v))) v))
true
(let [x (iterate #(do (print "test") (inc %1)) 1)] (rest x) (first x))
1
(into {} (map (fn [k v] (vector k v)) [:a :b :c] (iterate inc 0)))
{:a 0, :b 1, :c 2}
(def fib (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
#'user/fib
(take 15 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377)
(map second (take 10 (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(1 1 2 3 5 8 13 21 34 55)
(def fib (map (first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))))
#'user/fib
(defn fibo [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
#'user/fibo
(dorun (map #(println %) (take 5 (iterate #(list '() (list %)) '()))))
nil
"()\n(() (()))\n(() ((() (()))))\n(() ((() ((() (()))))))\n(() ((() ((() ((() (()))))))))\n"
(take 20 (let [a (iterate inc 1)] (for [x a y a] [x y])))
([1 1] [1 2] [1 3] [1 4] [1 5] [1 6] [1 7] [1 8] [1 9] [1 10] [1 11] [1 12] [1 13] [1 14] [1 15] [1 16] [1 17] [1 18] [1 19] [1 20])
(nth (map first (iterate (fn [[a b]] [b (+ a b)]) [0N 1N])) 500)
139423224561697880139724382870407283950070256587697307264108962948325571622863290691557658876222521294125N
(take-while #(>= % 0) (iterate #(.indexOf "a,bcde,f,gh" (int \,) (inc %)) 0))
(0 1 6 8)
((fn [n s] (map (partial take-nth n) (take n (iterate rest s)))) 3 (range 12))
((0 3 6 9) (1 4 7 10) (2 5 8 11))
(doseq [[name index] (map vector [:a :b :c] (iterate inc 0))] (prn (str index name)))
nil
"\"0:a\"\n\"1:b\"\n\"2:c\"\n"
(butlast (take-while seq (map (partial take 2) (iterate next [1 2 3 4 5 6]))))
((1 2) (2 3) (3 4) (4 5) (5 6))
(letfn [(odd-args [& xs] (filter odd? xs))] (take 5 (apply odd-args (iterate inc 0))))
(1 3 5 7 9)
(def yolo (take 2 (iterate (fn [a] (prn (str "PR" a)) (inc a)) 1)))
#'user/yolo
(first (last (take 5 (iterate (fn [[arr n]] [(conj arr n) (inc n)]) [[] 0]))))
[0 1 2 3]