Closed algoshipda closed 1 year ago
It might be a side-effect of Range function defaulting to Infinity. You can see #1801 for more informations. I think this will be fixed once we decide an implementation on #1801.
You can force the behaviour as a matter of fact:
Seq([1, 2, 3]).zip(Range(0, 3))
.reverse()
// results as expected: : [[3, 2], [2, 1], [1, 0]]
OK I think I do understand the issue:
actions are deferred to the latest moment possible, to [0, 1, 2]
is not generated before the reverse call.
When you call reverse
, then we calculate like that:
But as the "end" value is Infinity
, then it will take Infinity
, Infinity - 1
(resolved as Infinity
) and Infinity - 2
(same here).
Range
function and will force you to have a start
and end
value, so I will not fix this as you will forced to do so in your code (unless you specify Infinity
yourself, but then that's up to you 😅 )In a probably more complex example, you will need to do that:
const mySequence: Array<number> = getSequence();
Seq(mySequence).zip(Range(0, mySequence.length - 1)).reverse();
You can change the reverse
position if you think that it's more readable:
const mySequence: Array<number> = getSequence();
Seq(mySequence)reverse().zip(Range(mySequence.length - 1, 0));
Closing as you should explicitly set start and end values in your range in 4.x version
What happened
and run this code below with https://clojurescript.io/
I think those codes are equivalent and Clojure's output is correct output. Is this desired behavior?
Immutablejs Version: 4.0.0-rc.12