Added Sequence.take and Sequence.skip

These lazy iterator producing methods are useful when working with
arbitrary sequences and you need to skip or take some number of elements
at the start.
This commit is contained in:
Thorbjørn Lindeijer
2017-02-10 21:43:59 +01:00
parent 4fe3ad3f8b
commit f5d9443d0a
5 changed files with 155 additions and 0 deletions
+17
View File
@@ -125,6 +125,23 @@ It is a runtime error to call this on an empty sequence.
Similar to above, but uses `seed` for the initial value of the accumulator. If
the sequence is empty, returns `seed`.
### **skip**(count)
Creates a new sequence that skips the first `count` elements of the original
sequence.
The returned sequence is *lazy*. The first `count` elements are only skipped
once you start to iterate the returned sequence. Changes to the original
sequence will be reflected in the filtered sequence.
### **take**(count)
Creates a new sequence that iterates only the first `count` elements of the
original sequence.
The returned sequence is *lazy*. Changes to the original sequence will be
reflected in the filtered sequence.
### **toList**
Creates a [list][] containing all the elements in the sequence.