Created
May 1, 2014 05:08
-
-
Save bitmage/37fa6e453dd4970d4c2d to your computer and use it in GitHub Desktop.
sandbox experiment for tonight's meetup
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 make-seq [item] | |
(if (coll? item) | |
item | |
(list item))) | |
(defn flatten-once [items] | |
(apply concat (map make-seq items))) | |
(defn flatten-all [items] | |
(let [res (flatten-once items)] | |
(if (some coll? res) | |
(flatten-all res) | |
res))) | |
(flatten-all [1 2 [3] [2 [4]]]) | |
(flatten [1 2 [3] [2 [4]]]) | |
(defn my-flatten [x] | |
(filter (complement sequential?) | |
(rest (tree-seq sequential? seq x)))) | |
(sequential? []) | |
(sequential? #{}) | |
(flatten [1 2 {:a [1 2 [[3]]] :b 2}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment