Hullaballoonatic
12/21/2019, 6:01 PMval nums = listOf(1, 2, 3, 4, 5, 6)
val firstThree = nums[..2]
val lastThree = nums[-3..]
val trimEndsByTwo = nums[2..-3]
And the issue that I remember (note: not the only issue, perhaps) is that indexOf
returns -1
on an unfound element. so
val elementsToSeven = nums[..indexOf(7)]
would return the entirety of nums
, an unexpected value
C# 8.0 skirts around this issue by using ^
instead of -
as the end-orientation operator, and throws out of range for negative indices.
val lastThree = nums[^3..]
Would kotlin benefit from the same approach? I believe so. Especially given ^
is not currently used at allHullaballoonatic
12/21/2019, 6:06 PMHullaballoonatic
12/21/2019, 6:07 PMjimn
12/22/2019, 1:48 AMHullaballoonatic
12/22/2019, 3:13 AMjimn
12/22/2019, 3:47 AMHullaballoonatic
12/22/2019, 3:50 AM..
is unbounded or just bonded to something on the unbounded sidejimn
12/22/2019, 4:05 AMval firstThree = nums[..2]
first is required operator T.get(iterable<Int>)
as i have for reordering indexes.
next i guess is a Unary op for ".."(Int)->Iterator
for y[2..] we need infix fun Int.``..(Nothing)
as a guess anyways. but then the grammar needs to elide parsing a token for this special infix operator fun. i cannot think of similar existing operators within the existing grammarjimn
12/22/2019, 4:07 AMHullaballoonatic
12/22/2019, 9:40 PMHullaballoonatic
12/22/2019, 9:40 PMval fourToInfinity = 4..
val negativeInfinityToSix = ..6
Hullaballoonatic
12/22/2019, 9:43 PMval fourToInfinity = 4..
myData.id += 1
Hullaballoonatic
12/22/2019, 9:43 PMjimn
12/22/2019, 11:05 PMHullaballoonatic
12/22/2019, 11:05 PM(1..)
you mean? yeah, i'm fine with thatKy Leggiero
12/25/2019, 1:14 AMlist[7]
, list[wrapping = -2]
, list[clamping = 2000]
, list[orNull = 50]
, etc.jimn
12/25/2019, 7:31 AMKy Leggiero
12/26/2019, 6:04 AMHullaballoonatic
12/28/2019, 7:40 PMKy Leggiero
01/19/2020, 2:36 AM