File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ all: help
22
33EXTERNALS =externals
44
5- PYTHON ?= python2
5+ PYTHON ?= ` env which -a python2 python2.7 | head -n1 `
66PYTHONPATH =$$PYTHONPATH:$(EXTERNALS ) /pypy
77
88
Original file line number Diff line number Diff line change @@ -3079,3 +3079,23 @@ ex: (vary-meta x assoc :foo 42)"
30793079 :signatures [[rexegp-str opts]]}
30803080 [regexp-str opts]
30813081 (println (str regexp-str " " opts)))
3082+
3083+ (deftype Iterate [f x]
3084+ IReduce
3085+ (-reduce [self rf init]
3086+ (loop [col (rest self)
3087+ acc (rf init (first self))]
3088+ (if (reduced? acc)
3089+ @acc
3090+ (recur (rest col) (rf acc (first col))))))
3091+ ISeq
3092+ (-seq [self]
3093+ (cons x (lazy-seq* (fn [] (->Iterate f (f x)))))))
3094+
3095+ (defn iterate
3096+ {:doc "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of
3097+ side-effects"
3098+ :signatures [[f x]]
3099+ :added "0.1"}
3100+ [f x]
3101+ (->Iterate f x))
Original file line number Diff line number Diff line change 761761(t/ deftest test- memoize
762762 (let [f (memoize rand)]
763763 (t/ assert = (f) (f))))
764+
765+ (t/ deftest test- iterate
766+ (t/ assert = (take 5 (iterate inc 5 )) ' (5 6 7 8 9))
767+ (t/ assert = (reduce (fn [a v] (reduced " foo" )) 0 (iterate inc 1 )) " foo" )
768+ (t/ assert = (reduce (fn [a v] (if (< a 10 ) (+ a v) (reduced a))) 0 (iterate (partial + 2 ) 1 )) 16 ))
769+
You can’t perform that action at this time.
0 commit comments