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)
| 30 | // that must be a boolean or coercible to an integer. In the later case, the integer |
| 31 | // is converted to a boolean. |
| 32 | func 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 | |
| 53 | var compareInt = map[string]func(int64, int64) bool{ |
| 54 | "==": func(a, b int64) bool { return a == b }, |