Design decisions

41. std.seq complete surface (spec/lib/rationale/seq.md, 2026-11-21)

  • 41.1 Sequence functions take self: [D]T whenever they read by index, so one definition covers List<T>, [V]T, and Str with zero runtime dispatch and preserves D in return types (?D, Range<D>, [D]?D, [D.bounds]T). Reason: runs and pairs typed on List<T> forced manual loops on Str (cf2084h, cf2069e) and dropped domains on [V]T. Reverse: narrow signatures back to List<T>.
  • 41.2 chunk_by and run_ranges yield Range<D> instead of copied List<T> slices. Reason: runs_by allocated a List<T> per run and ran 50x slower than a manual loop on cf2135f; yielding Range<D> is O(1) extra space and zero allocations while giving r.len, a[r.first!], and for i in r:. Reverse: return materialized slices once borrowed slice views exist.
  • 41.3 prefix_fold and suffix_fold return [D.bounds]T (cut-indexed), while scan and suffix_scan return [D]T (element-indexed, no identity). Reason: matches std.prefix.Prefix1 and eliminates .ord / + 1 bookkeeping for outside-range queries op(pref[r.lo], suff[r.hi]) (cf2062e2). Reverse: drop prefix_fold/suffix_fold or return [D]T.
  • 41.4 General two-pointer loops stay user code; std.seq provides only fixed-window sliding_min/sliding_max and monotone-stack prev_less/next_less/prev_greater/next_greater (returning [D]?D). Reason: arbitrary two-pointer state is clearer as a 5-line loop than a 3-callback combinator, while sliding extrema and nearest-smaller/larger are universal, sentinel-prone patterns. Reverse: add or remove individual helpers in stdlib/seq.cp.