1
0
forked from Mirror/wren
Files
wren/test/core/sequence/skip.wren
Thorbjørn Lindeijer f5d9443d0a 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.
2017-02-10 21:43:59 +01:00

29 lines
722 B
Plaintext

class TestSequence is Sequence {
construct new() {}
iterate(iterator) {
if (iterator == null) return 1
if (iterator == 3) return false
return iterator + 1
}
iteratorValue(iterator) { iterator }
}
var test = TestSequence.new().skip(0)
System.print(test is Sequence) // expect: true
System.print(test) // expect: instance of SkipSequence
// Skipping 0 changes nothing
System.print(test.toList) // expect: [1, 2, 3]
// Skipping 1 works
System.print(test.skip(1).toList) // expect: [2, 3]
// Skipping more than length of sequence produces empty list
System.print(test.skip(4).isEmpty) // expect: true
// Skipping less than 0 changes nothing
System.print(test.skip(-10).toList) // expect: [1, 2, 3]