order.bend
bend-kit-collections@0.1.4.0 · 24 lines · 0 definitions
1# Order: comparators for OMap, List.sort, and other templates that take ~cmp.
2import Base
3
4def string.fin(c: Cmp, rest: Cmp) -> Cmp:
5 match c:
6 case LT{}:
7 LT{}
8 case EQ{}:
9 rest
10 case GT{}:
11 GT{}
12
13# Strings in code-point order, a prefix before its extensions. String.order gives
14# the same answers, but it rebuilds both strings on every call.
15def string(a: String, b: String) -> Cmp:
16 match a b:
17 case SNil{} SNil{}:
18 EQ{}
19 case SNil{} SCon{h, t}:
20 LT{}
21 case SCon{h, t} SNil{}:
22 GT{}
23 case SCon{Chr{+x}, s} SCon{Chr{+y}, t}:
24 string.fin(U32.cmp(x, y), string(s, t))