Skip to content

Instantly share code, notes, and snippets.

@m0smith
Last active December 14, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0smith/5169734 to your computer and use it in GitHub Desktop.
Save m0smith/5169734 to your computer and use it in GitHub Desktop.
Same as the core iterate function except the lazy sequence ends when the value is nil.
(defn iterate-while-1
[f x]
(when x
(cons x (lazy-seq (iterate-while f (f x))))))
(defn iterate-while
[f x]
(take-while identity (iterate f x)))
@m0smith
Copy link
Author

m0smith commented Mar 16, 2013

Upon further reflection, it is not needed. Simply apply take-while to iterate.

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