assoc-in can change a value at an index/key in vectors/maps. In maps, if an key does not exist, then it makes a new key/value pair. Is there something similiar for vectors (if an index does not exist, it makes a list with that value at that index) Something like:
(reduce (fn [g [x y]] (assoc-in g [x y] y ))
[]
(for [x (range 2)
y (range 2)]
[x y]))
above code generates:
[{1 1, 0 0} {1 1, 0 0}]
I want it to generate:
[[0 1] [0 1]]
Is this possible in a simple way?
Thanks
EDIT: To be more clear, I Just want it to generate nested vectors instead of nested maps (or a vector of maps) Now I put y as a value but that's just an example.
[[0 1] [0 1]]
means? Is it a vector of two vectors created from(range 2)
? or something else? – Alexey Kachayev