Lukasz Kalnik
10/02/2023, 12:33 PMlist.withIndex().partition { it.index < selectedIndex }
Pair<List<IndexedValue<T>>>
bram
10/02/2023, 12:44 PMLukasz Kalnik
10/02/2023, 12:45 PMbram
10/02/2023, 12:46 PMhho
10/02/2023, 12:51 PMAlejandro Serrano.Mena
10/02/2023, 1:08 PMval (before, after) = list.take(n) to list.drop(n)
Lukasz Kalnik
10/02/2023, 1:14 PMsubList()
, as it doesn't create additional listsEdoardo Luppi
10/02/2023, 1:14 PMYes, I suppose I won't get a nice one-linerExtension function containing two calls to
subList
if it's a readonly List<T>
Lukasz Kalnik
10/02/2023, 1:14 PMEdoardo Luppi
10/02/2023, 1:22 PMn
parts, you can even overload the div
operator.
val (one, two, three, four) = list / 4
Lukasz Kalnik
10/02/2023, 1:29 PMtake(n)
and drop(n)
ephemient
10/02/2023, 3:09 PMKlitos Kyriacou
10/02/2023, 5:01 PMAlthough I just realized my list can be smaller than the split index, so I have to go with @Alejandro Serrano.Mena’s approachInstead of creating two new lists, I would stick to Henning'sandtake(n)
drop(n)
subList
and just use splitIndex.coerceAtMost(size)
.Eric-Wubbo
10/03/2023, 5:24 PM