Design decisions

158. a.buckets() is the one domain-keyed grouping (2026-11-21)

  • Decision. buckets is a method on any keyed table: a.buckets() maps each value k to the keys i with a[i] == k, keyed by the value domain ([D]K -> [K]List<D>). Group by any domain-valued key with a.map(key).buckets(); an optional table gives a None bucket, read as b[Some(k)]. preimages (the [I]?V form) is folded in and removed, and the free buckets(key) becomes the method. a.group(by:) stays the hash-keyed form for keys that are not domains.
  • Why. The blind dmpg16g2 dream wanted R.group(pairs) -> [R]List, and its port spent a five-line push loop because group(by:) returns a HashMap. Library results stay in the keys they were given, so a domain-valued key should give a domain-keyed result. Overloading group by whether K is a domain is out (decision 127: no overloading by type), and buckets/preimages were two names for one job.
  • Reverse. Restore free buckets(key) and preimages(self: [I]?V) in spec/std/seq.cp and the callers in corpus/problems/{egoi23p7,dmpg16g2}.