(map count (take 5 (iterate next [1 2 3 4])))
(4 3 2 1 0)
(take-while (comp not nil?) (iterate next [1 2 3 4]))
([1 2 3 4] (2 3 4) (3 4) (4))
(take 1 (apply concat [[1 2 3] (iterate inc 0)]))
(1)
(take 20 (drop 4000 (iterate #(* 0.5 %) 100)))
(0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0)
((fn [aseq] (let [aseq (nth aseq 1000000)] aseq)) (iterate inc 1))
1000001
(reverse (take (count [1 2 3]) (iterate pop [1 2 3])))
([1] [1 2] [1 2 3])
(let [x (iterate inc 1)] [(take 5 x) (take 10 x)])
[(1 2 3 4 5) (1 2 3 4 5 6 7 8 9 10)]
(nth (iterate #(doall (map inc %)) [1 2 3]) 1000)
(1001 1002 1003)
(let [is (iterate #(+ 1 %) 0)] (take 5 is))
(0 1 2 3 4)
(partition 3 (take 30 (iterate #(mod (inc %) 256) 73)))
((73 74 75) (76 77 78) (79 80 81) (82 83 84) (85 86 87) (88 89 90) (91 92 93) (94 95 96) (97 98 99) (100 101 102))
((fn [aseq] (let [foo (nth aseq 1000000)] foo)) (iterate inc 1))
1000001
(take-while #(and (even? %) (< % 1000)) (iterate inc 1))
()
(chunked-seq? (seq (map first (take-while identity (iterate next [1 2 3])))))
false
(map * [3 52 1] (iterate #(/ % 10) 0.1M))
(0.3M 0.52M 0.001M)
(reduce :rocks nil (take 10 (iterate (fn [x] {:rocks x}) :rocks)))
{:rocks {:rocks {:rocks {:rocks {:rocks :rocks}}}}}
(take 10 (map take (iterate inc 0) (repeat [1 2 3])))
(() (1) (1 2) (1 2 3) (1 2 3) (1 2 3) (1 2 3) (1 2 3) (1 2 3) (1 2 3))
(take 5 (keep-indexed #(when (even? %2) [%1 %2]) (iterate inc 0)))
([0 0] [2 2] [4 4] [6 6] [8 8])
(take 5 (iterate (fn [x] (print "f: " x) (inc x)) 1))
(1 2 3 4 5)
"f: 1f: 2f: 3f: 4"
(take 5 (apply (fn [& xs] (filter odd? xs)) (iterate inc 0)))
(1 3 5 7 9)
(take 2 (iterate (fn [a] (prn (str "PR" a)) (inc a)) 1))
(1 2)
"\"PR1\"\n"
(take 15 (iterate (fn [[a b]] [b (+ a b)]) [1 0]))
([1 0] [0 1] [1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89] [89 144] [144 233] [233 377])
(take 10 (map (juxt identity #(* % %)) (iterate inc 0)))
([0 0] [1 1] [2 4] [3 9] [4 16] [5 25] [6 36] [7 49] [8 64] [9 81])
(take 1 (iterate (fn [a] (prn (str "PR" a)) (inc a)) 1))
(1)
(map #(vector %1 %2) [1 2 3] (iterate inc 5))
([1 5] [2 6] [3 7])
(take 6 (iterate rest (concat (range 2) (list 3 2 1))))
((0 1 3 2 1) (1 3 2 1) (3 2 1) (2 1) (1) ())
(apply (fn [& args] (take 3 args)) 1 (iterate inc 10))
(1 10 11)
(letfn [(f [& y] (first y))] (apply f (iterate inc 0)))
0
(def triangles (lazy-seq (cons 0 (map + triangles (iterate inc 1)))))
#'user/triangles
(let [x {:p {:p {:p nil}}}] (take-while identity (iterate :p x)))
({:p {:p {:p nil}}} {:p {:p nil}} {:p nil})
(take-while #(< % 100) (iterate #(+ % 2) 1))
(1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99)
(take-while #(< % 1000) (iterate #(* 2 %) 3))
(3 6 12 24 48 96 192 384 768)
(def facts (concat [1] (lazy-seq (map * facts (iterate inc 1)))))
#'user/facts
(take 4 (iterate #(map + [0 -1] %) [5 5]))
([5 5] (5 4) (5 3) (5 2))
(concat '(1 2 3 4) (take 5 (iterate inc 5)))
(1 2 3 4 5 6 7 8 9)
(map class (take 10 (iterate next (cycle (concat '(1) [2])))))
(clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle clojure.lang.Cycle)
(nth (iterate (comp #(apply hash-map %) (juxt identity identity)) {}) 4)
{{{{{} {}} {{} {}}} {{{} {}} {{} {}}}} {{{{} {}} {{} {}}} {{{} {}} {{} {}}}}}
(count (flatten (nth (iterate #(vec (repeat 10 %)) [:x]) 5)))
100000
(map * [3 52 1] (iterate #(/ % 10) 0.1))
(0.30000000000000004 0.52 0.001)
(first (apply concat (repeatedly #(do (println "foo") (iterate inc 0)))))
0
"foo\nfoo\nfoo\nfoo\n"
(take 4 (iterate #(mapv + [0 -1] %) [5 5]))
([5 5] [5 4] [5 3] [5 2])
(map #(prn %1 %2) [:a :b :c] (iterate inc 0))
(nil nil nil)
":a 0\n:b 1\n:c 2\n"
(first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))
[0 1]
(take 6 (map vector (iterate #(* 2 %) 2) (range)))
([2 0] [4 1] [8 2] [16 3] [32 4] [64 5])
(find (apply hash-map (interleave [:a :b :c] (iterate inc 0))) :b)
[:b 1]
(map #(into [] %) (partition 3 (take 9 (iterate inc 1))))
([1 2 3] [4 5 6] [7 8 9])
(take 4 (iterate meta '^^^{:key1 val1} {:key2 val2} {:key3 val3} a))
(a {:key3 val3} nil nil)
((comp first drop-while) (comp (partial not= 6) count) (iterate rest (range 1000)))
(994 995 996 997 998 999)
(first (drop-while #(< % 1000) (iterate #(* 2 %) 3)))
1536
(let [f (fn [x & y] x)] (apply f (iterate inc 0)))
0
(take 6 (iterate #(mapcat (juxt count first) (partition-by identity %)) [1]))
([1] (1 1) (2 1) (1 2 1 1) (1 1 1 2 2 1) (3 1 2 2 1 1))