I don't think this template function should be in any way authoritative, so let's namespace it.
59 lines
1.4 KiB
Plaintext
59 lines
1.4 KiB
Plaintext
-- main.mcl --
|
|
import "golang"
|
|
import "iter"
|
|
|
|
func itermap($a, $b) {
|
|
iter.map($a, $b)
|
|
}
|
|
|
|
func id($x) {
|
|
$x + $x
|
|
}
|
|
$fn_str = func($x) {
|
|
id($x)
|
|
}
|
|
$fn_int = func($x) {
|
|
id($x)
|
|
}
|
|
|
|
$in1 = [5, 4, 3, 2, 1,]
|
|
$in2 = ["a", "b", "c", "d", "e",]
|
|
$in3 = [1, 2, 3, 4, 5,]
|
|
$in4 = ["e", "d", "c", "b", "a",]
|
|
|
|
$out1 = iter.map($in1, $fn_int)
|
|
$out2 = iter.map($in2, $fn_str)
|
|
$out3 = itermap($in1, $fn_int)
|
|
$out4 = itermap($in2, $fn_str)
|
|
$out5 = iter.map($in3, func($x) { $x + $x })
|
|
$out6 = iter.map($in4, func($x) { $x + $x })
|
|
$out7 = itermap($in3, func($x) { $x + $x })
|
|
$out8 = itermap($in4, func($x) { $x + $x })
|
|
|
|
$t1 = golang.template("out1: {{ . }}", $out1)
|
|
$t2 = golang.template("out2: {{ . }}", $out2)
|
|
$t3 = golang.template("out3: {{ . }}", $out3)
|
|
$t4 = golang.template("out4: {{ . }}", $out4)
|
|
$t5 = golang.template("out5: {{ . }}", $out5)
|
|
$t6 = golang.template("out6: {{ . }}", $out6)
|
|
$t7 = golang.template("out7: {{ . }}", $out7)
|
|
$t8 = golang.template("out8: {{ . }}", $out8)
|
|
|
|
test "${t1}" {}
|
|
test "${t2}" {}
|
|
test "${t3}" {}
|
|
test "${t4}" {}
|
|
test "${t5}" {}
|
|
test "${t6}" {}
|
|
test "${t7}" {}
|
|
test "${t8}" {}
|
|
-- OUTPUT --
|
|
Vertex: test[out1: [10 8 6 4 2]]
|
|
Vertex: test[out2: [aa bb cc dd ee]]
|
|
Vertex: test[out3: [10 8 6 4 2]]
|
|
Vertex: test[out4: [aa bb cc dd ee]]
|
|
Vertex: test[out5: [2 4 6 8 10]]
|
|
Vertex: test[out6: [ee dd cc bb aa]]
|
|
Vertex: test[out7: [2 4 6 8 10]]
|
|
Vertex: test[out8: [ee dd cc bb aa]]
|