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

CLOVIS

02/19/2020, 1:02 PM
What are the main differences between
Iterator
and
Sequence
?
A Sequence can be transformed into an Iterator, even though it doesn't implement the Iterable interface.
m

Matej Drobnič

02/19/2020, 1:10 PM
So why is there special class instead of just using Iterable?
s

streetsofboston

02/19/2020, 1:15 PM
Why is there a Sequence interface/class?
Sequences are lazy, non-eager and immutable (no remove() on its Iterator).
Because of this, the hasNext() method of the Iterator from a Sequence may have some side-effects.
👍 1
f

Fleshgrinder

02/19/2020, 1:20 PM
Iterator
in Kotlin has no
remove
either, you would need to implement
MutableIterator
. 😉
💯 1
c

CLOVIS

02/20/2020, 2:50 PM
@streetsofboston does that mean Iterator is eager?
s

streetsofboston

02/20/2020, 2:54 PM
I meant ‘eager’ as the opposite of ‘lazy’. 🙂