Search code examples
clojure

Turning this list into a vector of sets


Does anyone have an idea how to convert this list of vectors into a vector of sets?

([#{2}] [#{1 2 3 4}] [#{5}] [#{3}])

result should be

[#{2} #{1 2 3 4} #{5} #{3}]

Solution

  • Note that the sets are just elements of the vectors.

    So, one way is to iterate (map) over the list of vectors and pick the first element of each vector (i.e. the set). This will build a list of these sets that you can then convert to a vector:

    user=> (vec (map first '([#{2}] [#{1 4 3 2}] [#{5}] [#{3}])))
    [#{2} #{1 4 3 2} #{5} #{3}]