Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn flat?
"Returns true if seq contains no sequences"
[seq]
(not-any? (fn [x] (isa? (type x) java.util.List)) seq))
(defn flatten
"Returns an unnested sequence from the non-sequence elements of seq
for example, it turns (1 (2) 3) into (1 2 3)"
[seq]
(if (isa? (type seq) java.util.List)
(if (flat? seq)
seq
(apply concat (map flatten seq)))
(list seq)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.