I am really new to clojure! How does `mapcat work?
mapcat function is just a shortcut for applying concat function to 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)
By using mapcat in combination with vector function you can interlace several collections:
=> (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'll get the same result using list function instead of vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With