ephemient
12/18/2021, 9:36 PMfun <T> MutableList<T>.splice(indices: IntRange, values: Iterable<T>)
? name debatable but that's what as Javascript, Perl, and Rust name the same function, and it's easily accessible via list[start..end] = values
in Python and Rubyephemient
12/18/2021, 9:36 PMfun <T> MutableList<T>.splice(indices: IntRange, values: Iterable<T>) {
var rangeSize = indices.endInclusive - indices.start + 1
var count = 0
var iterator = values.iterator()
while (count < rangeSize && iterator.hasNext()) {
this[indices.start + count++] = iterator.next()
}
if (count < rangeSize) {
subList(indices.start + count, indices.endInclusive + 1).clear()
} else if (values is List) {
addAll(indices.start + count, values.drop(count))
} else {
while (iterator.hasNext()) {
add(indices.start + count++, iterator.next())
}
}
}
but haven't really exercised it yetlouiscad
12/19/2021, 12:49 AMephemient
12/19/2021, 12:50 AM: Unit
return type is implied for { }
block defined functionsephemient
12/19/2021, 12:53 AM.subList(indices).toList()
first if that's what they want, but it's commonly used enough to warrant being built in here IMOedrd
12/19/2021, 8:48 PMoperator fun <T> MutableList<T>.set(indices: IntRange, values: Iterable<T>)
louiscad
12/19/2021, 11:38 PMmcpiroman
12/20/2021, 10:06 AMval a = list[2..5]
? I guess maybe it's difficult to choose whether it should be an alias for `subList`vs slice
.