Sequence operation classification regarding their statefulness and laziness.
#KT-16994 Fixed
This commit is contained in:
@@ -89,6 +89,21 @@ Java reflection provided by `kotlin-reflect` library.
|
||||
[Sequence][kotlin.sequences.Sequence] type that represents lazily evaluated collections. Top-level functions for instantiating sequences
|
||||
and extension functions for sequences.
|
||||
|
||||
## Classification of sequences
|
||||
|
||||
The sequence operations can be classified into the following groups regarding their state requirements:
|
||||
|
||||
- _stateless_ – operations like [kotlin.sequences.Sequence.map], [kotlin.sequences.Sequence.filter], which process each element independently;
|
||||
- _nearly stateless_ – operations which require a small constant amount of state to process an element, for example [kotlin.sequences.Sequence.take] or [kotlin.sequences.Sequence.drop];
|
||||
- _stateful_ – operations which require a significant amount of state, usually proportional to the number of elements in a sequence.
|
||||
|
||||
If the sequence operation returns another sequence, which is produced lazily, it's called _intermediate_, and otherwise the operation is _terminal_.
|
||||
Examples of terminal operations are [kotlin.sequences.Sequence.toList], [kotlin.sequences.Sequence.max].
|
||||
|
||||
Sequences can be iterated multiple times, however some sequence implementations might constrain themselves
|
||||
to be iterated only once. That is mentioned specifically in their documentation (e.g. [kotlin.sequences.generateSequence] overload).
|
||||
The latter sequences throw an exception on an attempt to iterate them the second time.
|
||||
|
||||
# Package kotlin.streams
|
||||
|
||||
Utility functions for working with Java 8 [streams](https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html).
|
||||
|
||||
Reference in New Issue
Block a user