41. std.seq complete surface (spec/lib/rationale/seq.md, 2026-11-21)
- 41.1 Sequence functions take
self: [D]Twhenever they read by index, so one definition coversList<T>,[V]T, andStrwith zero runtime dispatch and preservesDin return types (?D,Range<D>,[D]?D,[D.bounds]T). Reason:runsandpairstyped onList<T>forced manual loops onStr(cf2084h,cf2069e) and dropped domains on[V]T. Reverse: narrow signatures back toList<T>.
- 41.2
chunk_byandrun_rangesyieldRange<D>instead of copiedList<T>slices. Reason:runs_byallocated aList<T>per run and ran 50x slower than a manual loop oncf2135f; yieldingRange<D>is O(1) extra space and zero allocations while givingr.len,a[r.first!], andfor i in r:. Reverse: return materialized slices once borrowed slice views exist.
- 41.3
prefix_foldandsuffix_foldreturn[D.bounds]T(cut-indexed), whilescanandsuffix_scanreturn[D]T(element-indexed, no identity). Reason: matchesstd.prefix.Prefix1and eliminates.ord/+ 1bookkeeping for outside-range queriesop(pref[r.lo], suff[r.hi])(cf2062e2). Reverse: dropprefix_fold/suffix_foldor return[D]T.
- 41.4 General two-pointer loops stay user code;
std.seqprovides only fixed-windowsliding_min/sliding_maxand monotone-stackprev_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 instdlib/seq.cp.