94. xs.distinct() and consistent empty-sequence rule for fold(f) / min() / max() (2026-11-21)
- Decision.
- Add
distinct<S: Seq, T>(self: S) -> List<T>tostd.seqandstd.prelude: returns distinct values in first-seen order in O(n) expected time and O(n) space viaHashSet, across everySeq(List,ListView,[D]T,Str,StrView,Range). Keepdedup(mut a)/a.deduped()for adjacent-only O(n) deduplication (no hashing, e.g. aftersort()); no paralleluniquename. - Extend
xs.fold(f)across everySeqto accept both monoids (+,*,^,|,&,gcd,min,max,Monoid<T>, which return their identity when empty) and arbitrary binary functions(T, T) -> T, obeying the exact same empty-sequence rule asxs.min()/xs.max(): barexs.fold(f)returnsTand traps when empty, whilexs.fold(f)!orxs.fold(f) ?? dasks for?T(nonewhen empty). Also includeListViewandStrViewinexpr_maybe_opt_reducesoview.min() ?? d/view.max() ?? d/view.fold(f) ?? dbehave identically to owned sequences.
- Add
- Reason. Closes
research/frictions/cf2115a.md(a.fold(gcd)anda.distinct()on[D]T), eliminates the gap between monoid folds and arbitrary binary folds without inventing a second empty-sequence convention besidemin/max, and keeps adjacentdedup/dedupedcleanly separated from hashingdistinct. - Reverse. Remove
distinctfromstdlib/seq.cpandstdlib/prelude.cp, and removefold_seq/reduce_fold_fnfromcrates/cpl-ir/src/lower/call.rs.