How does mapcat work?

I'm really new to clojure! How does mapcat work?

+3


source to share


1 answer


mapcat

function
is just a shortcut to apply concat

function
in the result of map

function
:

=> (mapcat reverse [[3 2 1 0] [6 5 4] [9 8 7]])
(0 1 2 3 4 5 6 7 8 9)

=> (apply concat (map reverse [[3 2 1 0] [6 5 4] [9 8 7]]))
(0 1 2 3 4 5 6 7 8 9)

      

Literature:




Using mapcat

in conjunction with a function , you can interleave multiple collections: vector

=> (mapcat vector [1 2 3 4 5 6] [:q :w :e :r :t :y])
(1 :q 2 :w 3 :e 4 :r 5 :t 6 :y)

      

You will get the same result using list

function
instead vector

.

+5


source







All Articles