Design decisions

138. Sequences, search/DP and graph/tree API rounds (proposed, 2026-11-21)

  • Status. Proposed in spec/core/07-sequences.md, search-dp.md and graphs-trees.md; under review with Ryan. Sequence stubs follow round 2: Slice<S> replaces View<T>; scan (with from:) moved to std.prefix and returns Prefix; suffix folds are a.rev.scan(op); with_prev stays (path walks need the first step apart); List.take became take_all so take(k) is the view.
  • Sequences. One protocol, Seq<T> (iter() -> yields T); generators are the only iterator, push-based, and a generator value is a recipe rerun by each for. Indexed<D, T> adds O(1) s[i] and s.keys. The key type decides slicing: domain slices keep positions (a[l..=r][i] is a[i]), List/Str slices count from 0, since an Int offset has no identity and no type would stop rest[i] reading the wrong element. A literal is never a position into a domain slice. drop/take are O(1) views, q[r] = s is length-checked slice assignment, .collect() ends a chain, pre[v] is the inclusive prefix next to pre[c], and lint flags lazy chains consumed twice or with mutating closures. These replace 0-based View<T> and .at(i). a.map(f) stays indexed. Position queries are folds over a.keys (no argmin/order twins). a.scan(op) is cut-indexed; a.rev.scan(op) gives suffix folds on the same cuts. a.all becomes a.keys and V.all becomes V.range, since s.all(p) is the predicate and there is no overloading (§127).
  • Search/DP. peak/valley for unimodal search; F64 ends make an interval with bsearch/peak; tables are typed by state ([V.ranges] for interval DP with r.splits, [B.subsets] for masks); @memo fn caches in a table when all parameters are finite; speed-ups take the plain DP's cost function.
  • Graphs/trees. g[u] is the O(1) arcs view; algorithms take next; storage follows the vertex type; groupings return fresh domains; t.order (parents first) gives recursion-free tree DP.
  • Reverse. Each doc's "Open" section lists the alternative per call.