Last active
December 15, 2015 18:39
-
-
Save saolsen/5305308 to your computer and use it in GitHub Desktop.
reduce!
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 reducer | |
;; Removes 5 and the item after it from a sequence. | |
[{:keys [flag seq]} item] | |
(cond | |
flag {:flag false :seq seq} | |
(= item 5) {:flag true :seq seq} | |
:else {:flag false :seq (conj seq item)})) | |
(:seq (reduce reducer {:flag false :seq []} [1 2 3 4 5 6 7 8 9 10])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In just about any other functional language you'd use a tuple instead of a map. Maps make what the two values are more explicit though so I like them more.