]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | package stdlib |
2 | ||
3 | import ( | |
4 | "github.com/zclconf/go-cty/cty" | |
5 | "github.com/zclconf/go-cty/cty/function" | |
6 | ) | |
7 | ||
8 | var NotFunc = function.New(&function.Spec{ | |
9 | Params: []function.Parameter{ | |
10 | { | |
11 | Name: "val", | |
12 | Type: cty.Bool, | |
13 | AllowDynamicType: true, | |
14 | }, | |
15 | }, | |
16 | Type: function.StaticReturnType(cty.Bool), | |
17 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | |
18 | return args[0].Not(), nil | |
19 | }, | |
20 | }) | |
21 | ||
22 | var AndFunc = function.New(&function.Spec{ | |
23 | Params: []function.Parameter{ | |
24 | { | |
25 | Name: "a", | |
26 | Type: cty.Bool, | |
27 | AllowDynamicType: true, | |
28 | }, | |
29 | { | |
30 | Name: "b", | |
31 | Type: cty.Bool, | |
32 | AllowDynamicType: true, | |
33 | }, | |
34 | }, | |
35 | Type: function.StaticReturnType(cty.Bool), | |
36 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | |
37 | return args[0].And(args[1]), nil | |
38 | }, | |
39 | }) | |
40 | ||
41 | var OrFunc = function.New(&function.Spec{ | |
42 | Params: []function.Parameter{ | |
43 | { | |
44 | Name: "a", | |
45 | Type: cty.Bool, | |
46 | AllowDynamicType: true, | |
47 | }, | |
48 | { | |
49 | Name: "b", | |
50 | Type: cty.Bool, | |
51 | AllowDynamicType: true, | |
52 | }, | |
53 | }, | |
54 | Type: function.StaticReturnType(cty.Bool), | |
55 | Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { | |
56 | return args[0].Or(args[1]), nil | |
57 | }, | |
58 | }) | |
59 | ||
60 | // Not returns the logical complement of the given boolean value. | |
61 | func Not(num cty.Value) (cty.Value, error) { | |
62 | return NotFunc.Call([]cty.Value{num}) | |
63 | } | |
64 | ||
65 | // And returns true if and only if both of the given boolean values are true. | |
66 | func And(a, b cty.Value) (cty.Value, error) { | |
67 | return AndFunc.Call([]cty.Value{a, b}) | |
68 | } | |
69 | ||
70 | // Or returns true if either of the given boolean values are true. | |
71 | func Or(a, b cty.Value) (cty.Value, error) { | |
72 | return OrFunc.Call([]cty.Value{a, b}) | |
73 | } |