Open nmn opened 9 years ago
I would've expected this to just set those elements to -2, not actually remove them.
@CryZe I would've expected this to set those elements to -2 if the -2 wasn't in an array:
arr[2...4] = -2;
There's a difference between:
arr[2...4] = 0
and
arr[2...4] = [0];
that way both @nmn and @CryZe would be happy. @alongubkin I'm sorry, I don't feel your way in there.
Well, my proposal was straight from Swift. To be fair, the existing range splicing looked to be straight out of swift, so it felt completely obvious to me.
In swift:
var arr = [0,1,2,3,4,5,6,7,8,9]
arr[2...8] = [99]
// arr = [0, 1, 99, 9]
Also, you can shove in a bigger array instead:
var arr = [0, 1, 9];
arr[1..<2] = [1,2,3,4,5,6,7,8];
// arr = [0,1,2,3,4,5,6,7,8,9];
In Swift: arr[2...5] = -2
throws an error.
This whole thing feels natural to me and kind of similar to spread operators in ES6 Arrays:
var arr1 = [2,3,4,5];
var arr2 = [0, 1, ...arr1, 6,7,8,9];
// arr = [0,1,2,3,4,5,6,7,8,9];
Spider already supports:
This should work even if the number of elements on the right don't watch. For example: