Thomas
10/23/2024, 6:28 AMfun <T> List<T>.slice(fromIndex: Int, toIndex: Int): List<T>
but only:
fun <T> List<T>.slice(indices: IntRange): List<T>
Thomas
10/23/2024, 6:30 AMList<T>.subList
function has same issue, but flipped around: it has a double index paramter variant, but no IntRange
invariant.Thomas
10/23/2024, 6:33 AMsubList
and slice
behave differently, in both cases we are trying to supply an integer range conceptually.
I don't see why each of them only supports either double index parameter, or the IntRange
, but not both 🤔
Could this simply be an oversight when designing the stdlib?Kai Yuan
10/23/2024, 3:03 PMKai Yuan
10/23/2024, 3:03 PMlistOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).slice(1..5 step 2)
Thomas
10/24/2024, 2:57 AMstep
returns a IntProgression
which is a subtype of Iterable
, therefore invoking
fun <T> List<T>.slice(indices: Iterable<Int>): List<T>
so its not exactly the issue in here