(def my-nums (apply sorted-set (take 15 (iterate #(* 2 %) 3))))
#'user/my-nums
(->> :rocks (iterate (fn [x] {:rocks x})) (take 10) (reduce :rocks nil))
{:rocks {:rocks {:rocks {:rocks {:rocks :rocks}}}}}
(let [f (fn [& x] (first x))] (apply f (iterate inc 0)))
0
((comp first filter) (comp (partial = 10) count) (iterate rest (range 20)))
(10 11 12 13 14 15 16 17 18 19)
(->> (iterate inc 0) (reductions +) (take-while #(< % 100)) last)
91
(->> (iterate dec 10) (take 20) (map #(/ 6 %)) (seque 5))
(3/5 2/3 3/4 6/7 1 6/5 3/2 2 3)
(defn do-tails [s f] (doseq [item (take-while seq (iterate rest s))] (f item)))
#'user/do-tails
((nth (iterate comp next) 5) [1 2 3 4 5 6 7 8])
(2 3 4 5 6 7 8)
(take-while pos? (drop 1 (iterate #(.indexOf "foobar1barfoo1" "1" (+ 1 %)) -1)))
(6 13)
(apply (constantly nil) (for [x (take 20 (iterate inc 1))] (print x)))
nil
"12"
(apply (fn [x y & etc] (+ x y)) (iterate inc 0))
1
(map (fn [a b] [a b]) [1 2 3] (iterate inc 0))
([1 0] [2 1] [3 2])
((comp first drop-while) (comp (partial = 6) count) (iterate rest (range 10)))
(0 1 2 3 4 5 6 7 8 9)
(take 10 (iterate #(vector (last %) (apply + %)) [1 1]))
([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])
(take 10 (iterate (fn [[a b]] [b (+ a b)]) [0 1]))
([0 1] [1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55])
(map (partial take 2) (take-while seq (iterate rest [1 2 10 11])))
((1 2) (2 10) (10 11) (11))
(take 10 (iterate (fn [[a b]] [b (+ a b)]) [1 1]))
([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])
(map (fn [x i] [x i]) [:a :b :c] (iterate inc 0))
([:a 0] [:b 1] [:c 2])
(take 5 (iterate (fn [[x y]] [(inc x) (dec x)]) [0 0]))
([0 0] [1 -1] [2 0] [3 1] [4 2])
((comp first drop-while) (comp (partial not= 6) count) (iterate rest (range 10)))
(4 5 6 7 8 9)
(take-while #(< % 5) (map (fn [x] x) (iterate inc 1)))
(1 2 3 4)
(as-> 7 <> (iterate #(/ % 13) <>) (nth <> 17))
7/8650415919381337933
(take 20 (apply (fn [& xs] (filter even? xs)) (iterate inc 0)))
(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38)
(macroexpand '(take 5 (apply #(filter odd? %&) (iterate inc 0))))
(take 5 (apply (fn* [& %&] (filter odd? %&)) (iterate inc 0)))
(let [x {:p {:p {:p nil}}}] (rest (take-while identity (iterate :p x))))
({:p {:p nil}} {:p nil})
(take-while pos? (rest (iterate #(.indexOf "a,bcde,f,gh" (int \,) (inc %)) 0)))
(1 6 8)
(take 5 (iterate (fn [[x y]] [(inc x) (dec y)]) [0 0]))
([0 0] [1 -1] [2 -2] [3 -3] [4 -4])
(first (subseq (apply sorted-map (interleave (range 10) (iterate inc 85))) > 4))
[5 90]
(let [{a 1, b 2} (take 4 (iterate inc 1))] [a b])
[2 nil]
(take 10 (map #(- % 2) (iterate #(* % 3) 1)))
(-1 1 7 25 79 241 727 2185 6559 19681)
(map #(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]))
(take 2 (take 5 (iterate (fn [x] (do (println x) (inc x))) 1)))
(1 2)
"1\n"
(map (fn [x i] (prn x i)) [:a :b :c] (iterate inc 0))
(nil nil nil)
":a 0\n:b 1\n:c 2\n"
((comp first (partial nth (iterate (juxt second (partial apply +)) [1 1]))) 6)
13
((fn [_] nil) (nth (iterate #(map inc %) [1 2 3]) 1000))
nil
(for [x (iterate inc 0) :when (even? x) :while (< x 10)] x)
(0 2 4 6 8)
(->> (iterate dec 2) (take 5) (map #(/ 6 %)) (seque 5))
(3)
(let [x (fn [& more] (take 5 more))] (apply x (iterate inc 1)))
(1 2 3 4 5)
(first (flatten [[1 2 3] [4 5 6] [7 8 (iterate inc 0)]]))
1
(first (nth (iterate (fn [[a b]] [b (+ a b)]) [1 1]) 5))
8
(take-while #(not (nil? %)) (iterate #(if (neg? %) (inc %)) -10))
(-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0)
(map counted? (take 6 (iterate rest (concat (range 2) (list 3 2 1)))))
(false false false true true true)
(let [star (take 5 (iterate #(str "**" %) "*")) space (take 5 (iterate #(apply str (next %)) " "))] (dorun (map (comp println str) space star)))
nil
" *\n ***\n *****\n *******\n *********\n"
(let [x (iterate #(do (print "test") (inc %1)) 1)] (next x) (first x))
1
(let [v [1 2 3]] (= (take (count v) (iterate inc (first v))) v))
true
(defn fibb [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0N 1N])))
#'user/fibb
(apply hash-map (interleave (iterate inc 1) [{:a 1, :b 2} {:a 2, :b 3}]))
{1 {:a 1, :b 2}, 2 {:a 2, :b 3}}
(map (fn [val] (nth (iterate #(* 2 %) val) 6)) (range 0 10))
(0 64 128 192 256 320 384 448 512 576)
(def fibs (map second (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
#'user/fibs
(defn de-interleave [n coll] (map #(take-nth n %) (take n (iterate next coll))))
#'user/de-interleave