Last active
August 29, 2015 14:06
-
-
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)
This file contains hidden or 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 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