-
Notifications
You must be signed in to change notification settings - Fork 0
/
guards.mt
45 lines (41 loc) · 1.09 KB
/
guards.mt
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
exports(ZeroArgFunc, OneArgFunc, Tuple)
object OneArgFunc {
to coerce(specimen, ejector) {
if (specimen._respondsTo("run", 1)) {
return specimen
} else {
throw.eject(ejector, `$specimen is not a One argument function`)
}
}
}
object ZeroArgFunc {
to coerce(specimen, ejector) {
if (specimen._respondsTo("run", 0)) {
return specimen
} else {
throw.eject(ejector, `$specimen is not a Zero argument function`)
}
}
}
object Tuple {
match (verb, Tuple_arguments) {
if (verb == "get") {
object guard {
to coerce(specimen, ejector) {
List.coerce(specimen, ejector)
def specimen_size := specimen.size()
if (specimen_size != Tuple_arguments.size()) {
throw.eject(ejector, `missmatch of lengths between specimen and Tuple`)
}
var result := [].diverge()
var idx := 0
while (idx <= specimen_size) {
result.push(Tuple_arguments[idx].coerce(specimen[idx], ejector))
idx += 1
}
return result
}
}
}
}
}