This was the goal all along. Proper iteration without for loops. Yay! Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
29 lines
567 B
Plaintext
29 lines
567 B
Plaintext
import "datetime"
|
|
import "iter"
|
|
import "math"
|
|
|
|
$now = datetime.now()
|
|
|
|
# alternate every four seconds
|
|
$mod0 = math.mod($now, 8) == 0
|
|
$mod1 = math.mod($now, 8) == 1
|
|
$mod2 = math.mod($now, 8) == 2
|
|
$mod3 = math.mod($now, 8) == 3
|
|
$mod = $mod0 || $mod1 || $mod2 || $mod3
|
|
|
|
$fn = func($x) { # notable because concrete type is fn(t1) t2, where t1 != t2
|
|
len($x)
|
|
}
|
|
|
|
$in1 = if $mod {
|
|
["a", "bb", "ccc", "dddd", "eeeee",]
|
|
} else {
|
|
["ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "jjjjjjjjjj",]
|
|
}
|
|
|
|
$out1 = iter.map($in1, $fn)
|
|
|
|
$t1 = template("out1: {{ . }}", $out1)
|
|
|
|
test $t1 {}
|