Files
mgmt/examples/lang/map-iterator1.mcl
James Shubin 29eebd0d07 lang: core: Move template to golang namespace
I don't think this template function should be in any way authoritative,
so let's namespace it.
2024-09-13 15:51:24 -04:00

30 lines
593 B
Plaintext

import "datetime"
import "golang"
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 or $mod1 or $mod2 or $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 = golang.template("out1: {{ . }}", $out1)
test [$t1,] {}