Last active
December 13, 2015 18:58
-
-
Save lysu/4959203 to your computer and use it in GitHub Desktop.
mark from from plumbing.core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn unchunk | |
"Takes a seqable and returns a lazy sequence that | |
is maximally lazy and doesn't realize elements due to either | |
chunking or apply. | |
Useful when you don't want chunking, for instance, | |
(first awesome-website? (map slurp +a-bunch-of-urls+)) | |
may slurp up to 31 unneed webpages, wherease | |
(first awesome-website? (map slurp (unchunk +a-bunch-of-urls+))) | |
is guaranteed to stop slurping after the first awesome website. | |
Taken from http://stackoverflow.com/questions/3407876/how-do-i-avoid-clojures-chunking-behavior-for-lazy-seqs-that-i-want-to-short-ci" | |
[s] | |
(when (seq s) | |
(cons (first s) | |
(lazy-seq (unchunk (rest s)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment