Skip to content

Instantly share code, notes, and snippets.

@mpenet
Last active February 5, 2018 11:28
Show Gist options
  • Save mpenet/674c13bb8cc3b6fefa23f08bbea5446f to your computer and use it in GitHub Desktop.
Save mpenet/674c13bb8cc3b6fefa23f08bbea5446f to your computer and use it in GitHub Desktop.
like clojure.core sequence but without chunking
(defn unchunked-sequence [xform coll]
(->> coll
(clojure.lang.RT/iter)
(clojure.lang.TransformerIterator/create xform)
(clojure.lang.IteratorSeq/create)))
;; realizes 10 values
(first
(unchunked-sequence (comp (map #(do (prn %) %))
(partition-all 10))
(range 100)))
;; realizes all values
(first
(sequence (comp (map #(do (prn %) %))
(partition-all 10))
(range 100)))
@mpenet
Copy link
Author

mpenet commented Feb 5, 2018

since apparently sequence chunks by output it can end up causing the realisation of a lot of data from its inputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment