https://kotlinlang.org logo
#announcements
Title
# announcements
k

karelpeeters

12/04/2017, 9:04 PM
As I'm doing right now:
tipList = tipList.dropAt(index)
d

dave08

12/05/2017, 7:18 AM
If all you need is a sequence, you could do something like:
inline fun <T : Any> List<T>.dropAt(index: Int): Sequence<T> = buildSequence { yield(subList(0, index)); yield(subList(index + 1, size)) }
or similar with generateSequence...
k

karelpeeters

12/05/2017, 7:53 AM
Don't you need to actually
yield
values instead of partial lists? Unfortunately I do need an actual list, I need to "modify" an immutable list variable in-place.
d

dave08

12/05/2017, 8:01 AM
Oops youre right, you need yieldAll, not yield...
k

karelpeeters

12/05/2017, 8:02 AM
That exists too? I should really learn about everything coroutine-related sometime...
d

dave08

12/05/2017, 8:03 AM
Yup, it exists... its worth it to read the docs on kotlinx.coroutines... its pretty good!
If you need it immutable because of concurrency, you could also maybe use a mutable list and check out: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#actors ...
2 Views