On Wed, Apr 8, 2009 at 10:10 PM, Paul Drummond <paul.drumm...@iode.co.uk> wrote:
>
> I am looking for something similar to flatten (in contrib.seq-utils)
> but the function will only flatten one level deep:
>
> [ 1 2 3 [4 5 [6 7] ] ] ---> [ 1 2 3 4 5 [6 7] ]
>
> I have tried combining functions in the seq library and I've studied
> the code for flatten and tree-seq to look for hints but so far I can't
> see the way to do this. Can anyone help?

(defn flat1 [coll]
  (mapcat #(if (coll? %) % [%]) coll))

(flat1 [ 1 2 3 [4 5 [6 7] ] ])

--Chouser

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to