Last active
December 14, 2015 23:59
-
-
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.
This file contains hidden or 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 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))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upon further reflection, it is not needed. Simply apply take-while to iterate.