diff --git a/compare.go b/compare.go index e70c1fbb..6ab22754 100644 --- a/compare.go +++ b/compare.go @@ -9,10 +9,6 @@ import ( // The result will be 0 if l == r, -1 if l < r, and +1 if l > r. // This comparison is used by built-in operators and functions. func Compare(l, r any) int { - return compare(l, r) -} - -func compare(l, r any) int { return binopTypeSwitch(l, r, compareInt, func(l, r float64) any { @@ -44,7 +40,7 @@ func compare(l, r any) int { n = len(r) } for i := 0; i < n; i++ { - if cmp := compare(l[i], r[i]); cmp != 0 { + if cmp := Compare(l[i], r[i]); cmp != 0 { return cmp } } @@ -52,11 +48,11 @@ func compare(l, r any) int { }, func(l, r map[string]any) any { lk, rk := funcKeys(l), funcKeys(r) - if cmp := compare(lk, rk); cmp != 0 { + if cmp := Compare(lk, rk); cmp != 0 { return cmp } for _, k := range lk.([]any) { - if cmp := compare(l[k.(string)], r[k.(string)]); cmp != 0 { + if cmp := Compare(l[k.(string)], r[k.(string)]); cmp != 0 { return cmp } } diff --git a/func.go b/func.go index 165690a4..5545b278 100644 --- a/func.go +++ b/func.go @@ -602,7 +602,7 @@ func indices(vs, xs []any) any { return rs } for i := 0; i <= len(vs)-len(xs); i++ { - if compare(vs[i:i+len(xs)], xs) == 0 { + if Compare(vs[i:i+len(xs)], xs) == 0 { rs = append(rs, i) } } @@ -615,7 +615,7 @@ func funcIndex(v, x any) any { return nil } for i := 0; i <= len(vs)-len(xs); i++ { - if compare(vs[i:i+len(xs)], xs) == 0 { + if Compare(vs[i:i+len(xs)], xs) == 0 { return i } } @@ -629,7 +629,7 @@ func funcRindex(v, x any) any { return nil } for i := len(vs) - len(xs); i >= 0; i-- { - if compare(vs[i:i+len(xs)], xs) == 0 { + if Compare(vs[i:i+len(xs)], xs) == 0 { return i } } @@ -1188,7 +1188,7 @@ type rangeIter struct { } func (iter *rangeIter) Next() (any, bool) { - if compare(iter.step, 0)*compare(iter.value, iter.end) >= 0 { + if Compare(iter.step, 0)*Compare(iter.value, iter.end) >= 0 { return nil, false } v := iter.value @@ -1259,7 +1259,7 @@ func minMaxBy(vs, xs []any, isMin bool) any { } i, j, x := 0, 0, xs[0] for i++; i < len(xs); i++ { - if compare(x, xs[i]) > 0 == isMin { + if Compare(x, xs[i]) > 0 == isMin { j, x = i, xs[i] } } @@ -1290,7 +1290,7 @@ func sortItems(name string, v, x any) ([]*sortItem, error) { items[i] = &sortItem{v, xs[i]} } sort.SliceStable(items, func(i, j int) bool { - return compare(items[i].key, items[j].key) < 0 + return Compare(items[i].key, items[j].key) < 0 }) return items, nil } @@ -1323,7 +1323,7 @@ func funcGroupBy(v, x any) any { rs := []any{} var last any for i, r := range items { - if i == 0 || compare(last, r.key) != 0 { + if i == 0 || Compare(last, r.key) != 0 { rs, last = append(rs, []any{r.value}), r.key } else { rs[len(rs)-1] = append(rs[len(rs)-1].([]any), r.value) @@ -1348,7 +1348,7 @@ func uniqueBy(name string, v, x any) any { rs := []any{} var last any for i, r := range items { - if i == 0 || compare(last, r.key) != 0 { + if i == 0 || Compare(last, r.key) != 0 { rs, last = append(rs, r.value), r.key } } @@ -1826,9 +1826,9 @@ func funcBsearch(v, t any) any { return &func1TypeError{"bsearch", v, t} } i := sort.Search(len(vs), func(i int) bool { - return compare(vs[i], t) >= 0 + return Compare(vs[i], t) >= 0 }) - if i < len(vs) && compare(vs[i], t) == 0 { + if i < len(vs) && Compare(vs[i], t) == 0 { return i } return -i - 1 diff --git a/operator.go b/operator.go index 513dbfad..64b74b78 100644 --- a/operator.go +++ b/operator.go @@ -371,7 +371,7 @@ func funcOpSub(_, l, r any) any { L: for _, l := range l { for _, r := range r { - if compare(l, r) == 0 { + if Compare(l, r) == 0 { continue L } } @@ -525,25 +525,25 @@ func funcOpAlt(_, l, r any) any { } func funcOpEq(_, l, r any) any { - return compare(l, r) == 0 + return Compare(l, r) == 0 } func funcOpNe(_, l, r any) any { - return compare(l, r) != 0 + return Compare(l, r) != 0 } func funcOpGt(_, l, r any) any { - return compare(l, r) > 0 + return Compare(l, r) > 0 } func funcOpLt(_, l, r any) any { - return compare(l, r) < 0 + return Compare(l, r) < 0 } func funcOpGe(_, l, r any) any { - return compare(l, r) >= 0 + return Compare(l, r) >= 0 } func funcOpLe(_, l, r any) any { - return compare(l, r) <= 0 + return Compare(l, r) <= 0 }