Skip to content

Instantly share code, notes, and snippets.

@ekozhura
Last active August 29, 2015 14:06
Show Gist options
  • Save ekozhura/9da49c447f5956c156ab to your computer and use it in GitHub Desktop.
Save ekozhura/9da49c447f5956c156ab to your computer and use it in GitHub Desktop.
transform nested lists into flat list: (1 3 (4 66 33 67) 23 16) => (1 3 4 66 33 67 23 16)
(defn flat-lists
[ls]
(letfn [(rec-flat [rec-list ls]
(cond (empty? rec-list) ls
(seq? (first rec-list)) (rec-flat (rest rec-list)
(rec-flat (first rec-list) ls))
(not (seq? (first rec-list))) (rec-flat (rest rec-list)
(cons (first rec-list) ls))))]
(cond (seq? ls) (reverse (rec-flat ls '()))
:else (list ls))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment