When I have a chain of collection transformations,...
# announcements
e
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
subList
and
listIterator
are defined on lists, but not sequences.
b
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
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.