I have an array of tuples, where each tuple is a 2 tuple with a key and a value. What would be the cleanest way to convert this array of tuples into a hash-map?
user=> (into {} [[:a 1] [:b 2]]) {:a 1, :b 2}
A map is a sequence of MapEntry elements. Each MapEntry is a vector of a key and value. The tuples in the question are already in the form of a MapEntry, which makes things convenient. (That's also why the into
solution is a good one.)
user=> (reduce conj {} [[:a 1] [:b 2]]) {:b 2, :a 1}
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