Would you use such functions? `fun List<E>.s...
# stdlib
l
Would you use such functions?
fun 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?
b
Could be useful. Maybe a parameter to decide if it's inclusive or not could be nice too.
d
There is already
dropWhile
, 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 variant
l
@bod Oh, that's right… now I don't think it'd satisfy my actual use case as is… And yes @diesieben07, I stumbled on 'dropWhile` just before your message, suits my use case quite well finally, with the same "cost".
d
A way to achieve exactly what you want is:
Copy code
list.subList(list.lastIndexOf(element) + 1, list.size)
If the element is not found, you get the whole list.