aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonrad Hinsen <konrad.hinsen@laposte.net>2009-01-26 08:10:52 +0000
committerKonrad Hinsen <konrad.hinsen@laposte.net>2009-01-26 08:10:52 +0000
commit30be1742936bcf76839b269a545d87b566dd8a73 (patch)
treef1e8dab0968f64d33d5a227e96630c3d8e6f97d2 /src
parent336e64802cb60649c72271332f7bc14ece06944d (diff)
stream-utils: use new fn interface to stream iters
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/stream-utils.clj18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/clojure/contrib/stream-utils.clj b/src/clojure/contrib/stream-utils.clj
index 4bcca548..fd4e6a04 100644
--- a/src/clojure/contrib/stream-utils.clj
+++ b/src/clojure/contrib/stream-utils.clj
@@ -43,22 +43,12 @@
;; Stream transformers
-; Going from a stream through an iter to another stream requires at
-; one point to wrap the iter in a function that provides the generator
-; interface. Life would be easier if iterators were callable and thus
-; usable directly as generators! This function (1) creates an iter on
-; its stream argument and (2) wraps that iter into a function with a
-; generator interface.
-(defn iter-as-generator [s]
- "Return a generator that returns items obtained from an iterator on s"
- (let [iter (stream-iter s)]
- (fn [eos] (next! iter eos))))
-
(defn drop-first
"Return a stream that returns the elements of s except for the first n ones."
[n s]
(let [eos (Object.)
- gen (iter-as-generator s)]
+ iter (stream-iter s)
+ gen (fn [eos] (next! iter eos))]
(doseq [_ (range n)] (gen eos))
(stream gen)))
@@ -101,7 +91,7 @@
; and converts the resulting generator into a stream.
(defmacro stream-transformer
[stream-args & body]
- `(stream (let [~stream-args (map iter-as-generator ~stream-args)]
+ `(stream (let [~stream-args (map stream-iter ~stream-args)]
(with-monad generator ~@body))))
@@ -122,7 +112,7 @@
(defmacro stream-transformer-cond
[stream-args & body]
`(stream (remove-skip
- (let [~stream-args (map iter-as-generator ~stream-args)]
+ (let [~stream-args (map stream-iter ~stream-args)]
(with-monad generator-cond ~@body)))))