File: map-iterator2.mcl

package info (click to toggle)
mgmt 0.0.26.git.2024.10.25.85e1d6c0e8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,364 kB
  • sloc: sh: 2,471; yacc: 1,285; makefile: 543; python: 196; lisp: 77
file content (50 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
$moda = $mod0 or $mod1 or $mod2 or $mod3

$mod4 = math.mod($now, 8) == 4
$mod5 = math.mod($now, 8) == 5
$mod6 = math.mod($now, 8) == 6
$mod7 = math.mod($now, 8) == 7
$modb = $mod4 or $mod5 or $mod6 or $mod7

$fn = if $moda {
	func($x) { # notable because concrete type is fn(t1) t2, where t1 != t2
		len($x)
	}
} else {
	func($x) { # notable because concrete type is fn(t1) t2, where t1 != t2
		-1*len($x)
	}
}

$in1 = if $modb {
	["a", "bb", "ccc", "dddd", "eeeee",]
} else {
	["ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "jjjjjjjjjj",]
}

$out1 = iter.map($in1, $fn)

$t1 = golang.template("out1: {{ . }}", $out1)

test [$t1,] {}

file "/tmp/mgmt/map" {
	state => $const.res.file.state.exists,
	content => $t1,
}

file "/tmp/mgmt/" {
	state => $const.res.file.state.exists,
}