Created
July 15, 2011 00:21
-
-
Save gfredericks/1083792 to your computer and use it in GitHub Desktop.
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
; user=> (flat [[[[[4 55] 6] [6 6 [5 4]]]]]) | |
; [4 55 6 6 6 5 4] | |
(defn flat | |
[coll] | |
(loop [res [], coll coll, stack ()] | |
(if (empty? coll) | |
(if (empty? stack) | |
res | |
(recur res (first stack) (rest stack))) | |
(let [[x & xs] coll] | |
(if (coll? x) | |
(recur res x (cons xs stack)) | |
(recur (conj res x) xs stack)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment