Insert an element into a sequence when displayed above it in Clojure

I have a vector like [["H"] ["B"] ["ER"] ["W"]] and I need a shape vector [["H"] ["B"] ["E"] [" R "] [" W "]] with the natural separation of E and R.

I am very familiar with the map (and reduce) and use them a lot, but for some reason I can’t figure out how easy it is to use the map.

Is it possible to display two or more elements for each input they enter from a sequence? If so, how?

+4
source share
1 answer

mapcat - this is what you are looking for.

mapcat . . :

(vec
  (mapcat #(map (comp vector str) (first %))
          [["H"] ["B"] ["ER"] ["W"]]))
+4

Source: https://habr.com/ru/post/1653586/


All Articles