Change one wagon three ways: arr.with(i, v) brings a new train and Mr. Wiryo copies everything, arr[i] = v reloads train #1 itself, and the manual slice way…
The key idea
arr.with(i, v) is the non-mutating twin of arr[i] = v
Try it in this playground
with against arr[i] = v Run both to the end: a new train against the same train.
From the back Use with with a negative i: the place counts from the last wagon.
Past the end Slide i off the train: with throws a RangeError before reading anything.
Let React render With setItems, use with: Object.is(arr, baru) is false.