Code: Select all
; chained manipulations
s0 := Sequence([1, 2, 3, 4, 5, 6, 7])
.filter(x => Mod(x, 2) = 1) ; = 1 3 5 7
.map(x => x + 100) ; = 101 103 105 107
.take(3) ; = 101 103 105
.drop(1) ; = 103 105
; infinity sequence generated by 1 seed
s1 := Sequence.byOne(1, x => x * 2) ; = 1 2 4 8 16 ...
; endless fibonacci numbers generated by 2 seeds
fib := Sequence.byTwo(1, 1, (i, j) => i + j) ; = 1 1 2 3 5 8 13 ...
Using Sequence, the loops processes can be easily cast to functional-style, which is lazy and powerful, like:
Code: Select all
loopFiles(pattern, mode) => Sequence of FileObject
loopParse(str, delimiter) => Sequence of String