Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Last active May 10, 2019 19:18
Show Gist options
  • Save aarkerio/0d756f2e30813ddbc0eb9e75ec83590f to your computer and use it in GitHub Desktop.
Save aarkerio/0d756f2e30813ddbc0eb9e75ec83590f to your computer and use it in GitHub Desktop.
(defn flat?
"true if there is no sequences"
[seq]
(not-any? (fn [x] (isa? (type x) java.util.List)) seq))
(defn my-flatten
"Returns flat sequence"
[seq]
(if (isa? (type seq) java.util.List)
(if (flat? seq)
seq
(apply concat (map flatten seq)))
(list seq)))
Test:
(my-flatten [1,[7,0],2,[3,8, [7]],4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment