Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to flatten a seq containing seq of vectors

Tags:

clojure

I have a seq in this format -

( ([2 3 4] [7 6 8]) (["hh" 5] [9 8]))

I want to flatten it so that its a seq of vectors instead of a seq of seq of vectors. How do I do that ?

Also flatten completely flattens it, I want to only flatten it one level to - ([2 3 4] [ 7 6 8] ["hh" 5] [9 8])

like image 472
murtaza52 Avatar asked Sep 21 '12 05:09

murtaza52


2 Answers

Try concat:

(apply concat seq)
like image 189
nneonneo Avatar answered Oct 20 '22 00:10

nneonneo


(reduce (fn[h v]
          (reduce (fn[s e] (conj s e)) h v))
        [] [[[2 3 4] [7 6 8]] [["hh" 5] [9 8]]])
like image 41
Hamza Yerlikaya Avatar answered Oct 19 '22 23:10

Hamza Yerlikaya