lang: core: iter: Add filter iterator function
This was fun to write and adds a new core iterator function.
This commit is contained in:
14
examples/lang/filter-iterator0.mcl
Normal file
14
examples/lang/filter-iterator0.mcl
Normal file
@@ -0,0 +1,14 @@
|
||||
import "iter"
|
||||
import "math"
|
||||
|
||||
$fn1 = func($x) {
|
||||
math.mod($x, 2) == 0 # is even?
|
||||
}
|
||||
|
||||
$in1 = [8, -1, 0, 2, 4, 5, 13,]
|
||||
|
||||
$out1 = iter.filter($in1, $fn1)
|
||||
|
||||
$t1 = template("out1: {{ . }}", $out1)
|
||||
|
||||
test [$t1,] {}
|
||||
14
examples/lang/filter-iterator1.mcl
Normal file
14
examples/lang/filter-iterator1.mcl
Normal file
@@ -0,0 +1,14 @@
|
||||
import "iter"
|
||||
import "math"
|
||||
|
||||
$fn1 = func($x) {
|
||||
math.mod(len($x), 2) == 0 # is length even ?
|
||||
}
|
||||
|
||||
$in1 = ["xxxxxx", "a", "bb", "ccc", "dddd", "eeeee",]
|
||||
|
||||
$out1 = iter.filter($in1, $fn1)
|
||||
|
||||
$t1 = template("out1: {{ . }}", $out1)
|
||||
|
||||
test [$t1,] {}
|
||||
Reference in New Issue
Block a user