diff options
Diffstat (limited to 'tpl/collections/collections.go')
-rw-r--r-- | tpl/collections/collections.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 69d0f7042..3839ad472 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -242,17 +242,16 @@ func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, err } // In returns whether v is in the set l. l may be an array or slice. -func (ns *Namespace) In(l interface{}, v interface{}) bool { +func (ns *Namespace) In(l interface{}, v interface{}) (bool, error) { if l == nil || v == nil { - return false + return false, nil } lv := reflect.ValueOf(l) vv := reflect.ValueOf(v) if !vv.Type().Comparable() { - // TODO(bep) consider adding error to the signature. - return false + return false, errors.Errorf("value to check must be comparable: %T", v) } // Normalize numeric types to float64 etc. @@ -269,15 +268,15 @@ func (ns *Namespace) In(l interface{}, v interface{}) bool { lvvk := normalize(lvv) if lvvk == vvk { - return true + return true, nil } } case reflect.String: if vv.Type() == lv.Type() && strings.Contains(lv.String(), vv.String()) { - return true + return true, nil } } - return false + return false, nil } // Intersect returns the common elements in the given sets, l1 and l2. l1 and |