Last active
August 29, 2015 13:57
-
-
Save stathissideris/9349299 to your computer and use it in GitHub Desktop.
safe walk
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 prewalkseq | |
"Like prewalk but only for seqs and uses zippers." | |
[f s] | |
(loop [z (zip/seq-zip s)] | |
(if (zip/end? z) | |
(zip/root z) | |
(recur (zip/next (zip/replace z (f (zip/node z)))))))) | |
;;replace zip/seq-zip with zip/vector-zip for vectors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment