-
Notifications
You must be signed in to change notification settings - Fork 22
/
all.go
49 lines (39 loc) · 1.32 KB
/
all.go
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
package macros
import (
. "github.com/kocircuit/kocircuit/lang/circuit/eval"
. "github.com/kocircuit/kocircuit/lang/circuit/model"
. "github.com/kocircuit/kocircuit/lang/go/eval"
. "github.com/kocircuit/kocircuit/lang/go/eval/symbol"
. "github.com/kocircuit/kocircuit/lang/go/kit/util"
)
func init() {
RegisterEvalMacro("All", new(EvalAllMacro))
}
type EvalAllMacro struct{}
func (m EvalAllMacro) MacroID() string { return m.Help() }
func (m EvalAllMacro) Label() string { return "all" }
func (m EvalAllMacro) MacroSheathString() *string { return PtrString("All") }
func (m EvalAllMacro) Help() string { return "All" }
func (m EvalAllMacro) Doc() string {
return `
The builtin function All() is designed to facilitate branching on
the condition that a few values are all non-empty.
All() accepts any number of named arguments.
If all arguments are non-empty, All() returns a structure containing all named arguments as fields.
If any one of the arguments is empty, All() returns the empty value.`
}
func (EvalAllMacro) Invoke(span *Span, arg Arg) (returns Return, effect Effect, err error) {
a := arg.(*StructSymbol)
all := true
for _, field := range a.Field {
if IsEmptySymbol(field.Value) {
all = false
break // for
}
}
if all && len(a.Field) > 0 {
return a, nil, nil
} else {
return EmptySymbol{}, nil, nil
}
}