On Tue, Nov 10, 2009 at 1:00 AM, Richard Newman <holyg...@gmail.com> wrote:

> > I have a vector a [ [2 3] [4 5] [6 7] ]
> >
> > And I want to be able to get [2 3 4 5 6 7]
>
> user=> (reduce into [ [2 3] [4 5] [6 7] ])
> [2 3 4 5 6 7]
>

This and another solution have already been posted, but there's also:

(vec (apply concat [ [2 3] [4 5] [6 7] ]))

(vec (mapcat identity [ [2 3] [4 5] [6 7] ]))

(into [] (apply concat [ [2 3] [4 5] [6 7] ]))

(into [] (mapcat identity [ [2 3] [4 5] [6 7] ]))

(into [] (remove vector? (tree-seq vector? seq [ [2 3] [4 5] [6 7] ])))

of which the last will also do e.g. [[2 [4 5]] [[8 9] [11 1]] [17]].

Of course, then we're getting pretty close to the implementation of flatten,
which is

(filter (complement sequential?)
          (rest (tree-seq sequential? seq x)))

(apparently whoever wrote it never heard of remove). :)

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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