louiscad
07/08/2020, 12:15 PMfun List<E>.subListAfterFirst(element: E): List<E>
fun List<E>.subListAfterLast(element: E): List<E>
They could also take a predicate instead of an element.
Maybe there's already a good alternative that I didn't think of or found?bod
07/08/2020, 12:18 PMdiesieben07
07/08/2020, 12:22 PMdropWhile
, which is almost what you want except that with list.dropWhile { it != element }
you are checking for the first element to include instead of the last element to drop. Maybe a useful variantlouiscad
07/08/2020, 12:22 PMdiesieben07
07/08/2020, 12:26 PMlist.subList(list.lastIndexOf(element) + 1, list.size)
If the element is not found, you get the whole list.