Debian Codegraph @

lang/interpret_test/TestAstFunc2/map-iterator1.txtar

raw
1 -- main.mcl --
2 import "golang"
3 import "iter"
4
5 func itermap($a, $b) {
6 iter.map($a, $b)
7 }
8
9 func id($x) {
10 $x + $x
11 }
12 $fn_str = func($x) {
13 id($x)
14 }
15 $fn_int = func($x) {
16 id($x)
17 }
18
19 $in1 = [5, 4, 3, 2, 1,]
20 $in2 = ["a", "b", "c", "d", "e",]
21 $in3 = [1, 2, 3, 4, 5,]
22 $in4 = ["e", "d", "c", "b", "a",]
23
24 $out1 = iter.map($in1, $fn_int)
25 $out2 = iter.map($in2, $fn_str)
26 $out3 = itermap($in1, $fn_int)
27 $out4 = itermap($in2, $fn_str)
28 $out5 = iter.map($in3, func($x) { $x + $x })
29 $out6 = iter.map($in4, func($x) { $x + $x })
30 $out7 = itermap($in3, func($x) { $x + $x })
31 $out8 = itermap($in4, func($x) { $x + $x })
32
33 $t1 = golang.template("out1: {{ . }}", $out1)
34 $t2 = golang.template("out2: {{ . }}", $out2)
35 $t3 = golang.template("out3: {{ . }}", $out3)
36 $t4 = golang.template("out4: {{ . }}", $out4)
37 $t5 = golang.template("out5: {{ . }}", $out5)
38 $t6 = golang.template("out6: {{ . }}", $out6)
39 $t7 = golang.template("out7: {{ . }}", $out7)
40 $t8 = golang.template("out8: {{ . }}", $out8)
41
42 test "${t1}" {}
43 test "${t2}" {}
44 test "${t3}" {}
45 test "${t4}" {}
46 test "${t5}" {}
47 test "${t6}" {}
48 test "${t7}" {}
49 test "${t8}" {}
50 -- OUTPUT --
51 Vertex: test[out1: [10 8 6 4 2]]
52 Vertex: test[out2: [aa bb cc dd ee]]
53 Vertex: test[out3: [10 8 6 4 2]]
54 Vertex: test[out4: [aa bb cc dd ee]]
55 Vertex: test[out5: [2 4 6 8 10]]
56 Vertex: test[out6: [ee dd cc bb aa]]
57 Vertex: test[out7: [2 4 6 8 10]]
58 Vertex: test[out8: [ee dd cc bb aa]]