Suppose I have an immutable.js List
like this:
var xs = Immutable.fromJS([{key: "k", text: "foo"}])
I want to transform that into a Map that looks like this:
var ys = Immutable.fromJS({k: {key: "k", text: "foo"}})
How do I turn xs
into ys
idiomatically in immutable.js?
By idiomatically I mean that any intermediate structures should be immutable.js structures, and I think that any intermediate steps would use iterable composition instead of creating full-size intermediate representations.
Edit: I've created a jsperf benchmark comparing the answers provided so far. Both non-mutating solutions feel fairly idiomatic to me; I may hold out and let votes decide the chosen answer or hold out until we can gather a collection of roughly equally idiomatic techniques.