Created
February 27, 2020 17:40
-
-
Save scotthaleen/77b60a6b4a3a95e338fe513e301be27e to your computer and use it in GitHub Desktop.
This file contains 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 flattener | |
[input flattened?] | |
(((fn [f] (f f)) | |
(fn [f] | |
(fn [x xs] | |
(if (flattened? x) | |
(cons x ((f f) (first xs) (rest xs))) | |
(if (empty? x) | |
xs | |
((f f) (first x) ((f f) (rest x) xs))))))) | |
(first input) (rest input))) | |
(def tree [1 | |
[2 3 | |
[4 | |
[[5 6] 8]]] | |
[9 4] | |
[10 20] | |
[[5]]]) | |
(flattener tree integer?) | |
;;=> (1 2 3 4 5 6 8 9 4 10 20 5) | |
;;y-combinator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment