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

eekboom

10/29/2019, 1:53 PM
When I have a chain of collection transformations, is it always possible to easily convert that to operations on a sequence? In other words: Is there any operation that I can use in a chain of collection operations, but not on a sequence?
m

marstran

10/29/2019, 2:15 PM
subList
and
listIterator
are defined on lists, but not sequences.
b

Burkhard

10/29/2019, 2:22 PM
subList
can be replaced with
subSequence
on sequences.
listIterator
however is special, since it returns an iterator that allows traversal in both directions. This is not possible for sequences so AFAIK it’s the only function that does not translate to sequences.
But in most cases
iterator
is good enough.
e

eekboom

10/29/2019, 2:49 PM
Thanks a lot! Those operations currently don’t bother me, because I am converting lots of Java stream pipelines to Kotlin (and Java streams have no subList/listIterator). I was just asking myself if I need to decide now to use either collections or sequence operations.
I prefer collection operations for brevity (and ease of debugging) and would convert to sequences later if needed for performance reasons.
3 Views