Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/99641 to your computer and use it in GitHub Desktop.
Save cgrand/99641 to your computer and use it in GitHub Desktop.
(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