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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
package stdlib
import (
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
)
var NotFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "val",
Type: cty.Bool,
AllowDynamicType: true,
AllowMarked: true,
},
},
Type: function.StaticReturnType(cty.Bool),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
return args[0].Not(), nil
},
})
var AndFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "a",
Type: cty.Bool,
AllowDynamicType: true,
AllowMarked: true,
},
{
Name: "b",
Type: cty.Bool,
AllowDynamicType: true,
AllowMarked: true,
},
},
Type: function.StaticReturnType(cty.Bool),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
return args[0].And(args[1]), nil
},
})
var OrFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "a",
Type: cty.Bool,
AllowDynamicType: true,
AllowMarked: true,
},
{
Name: "b",
Type: cty.Bool,
AllowDynamicType: true,
AllowMarked: true,
},
},
Type: function.StaticReturnType(cty.Bool),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
return args[0].Or(args[1]), nil
},
})
// Not returns the logical complement of the given boolean value.
func Not(num cty.Value) (cty.Value, error) {
return NotFunc.Call([]cty.Value{num})
}
// And returns true if and only if both of the given boolean values are true.
func And(a, b cty.Value) (cty.Value, error) {
return AndFunc.Call([]cty.Value{a, b})
}
// Or returns true if either of the given boolean values are true.
func Or(a, b cty.Value) (cty.Value, error) {
return OrFunc.Call([]cty.Value{a, b})
}
|