Created
August 8, 2016 06:18
-
-
Save JonathanGTH/a29c196a4365555ae8b00d12821f021b to your computer and use it in GitHub Desktop.
Flatten Arbitrary Arrays in Order
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
(ns citus-byte) | |
(defn flatten2 | |
{:static true} | |
[x] | |
(letfn [(flat [coll] | |
(lazy-seq | |
(when-let [c (seq coll)] | |
(let [x (first c)] | |
(if (sequential? x) | |
(concat (flat x) (flat (rest c))) | |
(cons x (flat (rest c))))))))] | |
(if (sequential? x) (flat x) x))) | |
;; Testing as (flatten2 [[1,2,[3]],4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment