MCPcopy Create free account
hub / github.com/brimdata/super / CompareBool

Function CompareBool

runtime/sam/expr/boolean.go:32–51  ·  view source on GitHub ↗

CompareBool returns a Predicate that compares super.Values to a boolean literal that must be a boolean or coercible to an integer. In the later case, the integer is converted to a boolean.

(op string, pattern bool)

Source from the content-addressed store, hash-verified

30// that must be a boolean or coercible to an integer. In the later case, the integer
31// is converted to a boolean.
32func CompareBool(op string, pattern bool) (Boolean, error) {
33 compare, ok := compareBool[op]
34 if !ok {
35 return nil, fmt.Errorf("unknown bool comparator: %s", op)
36 }
37 return func(val super.Value) super.Value {
38 val = val.Under()
39 if val.IsNull() {
40 return super.Null
41 }
42 if val.IsError() {
43 return val
44 }
45 if val.Type().ID() != super.IDBool {
46 return super.False
47 }
48 b := val.Bool()
49 return super.NewBool(compare(b, pattern))
50 }, nil
51}
52
53var compareInt = map[string]func(int64, int64) bool{
54 "==": func(a, b int64) bool { return a == b },

Callers 1

ComparisonFunction · 0.85

Calls 8

NewBoolFunction · 0.92
compareFunction · 0.85
UnderMethod · 0.80
IsNullMethod · 0.80
IsErrorMethod · 0.80
BoolMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected