Repository navigation
Description
Summary
Implement the full tier-1 iterator/collection operation surface as generic With stdlib code, then route comprehensions and collection pipelines through those operations. Current coverage is a small subset of §13.3.
Spec
docs/with-specification.md:5215-5223 defines collection operations as the common pipeline layer for literals, comprehensions, and iterator processing. docs/with-specification.md:5225-5294 lists required lazy transformations and eager consumers, including filter_map, flatten, drop, take_while, drop_while, enumerate, chain, peekable, chunks, windows, dedup, unique, intersperse, scan, step_by, zip_with, reduce, sum, product, count, min, max, find, position, any, all, none, for_each, join, sorted, group_by, partition, and unzip. docs/with-specification.md:5296-5334 also specifies standalone constructors and HashMap convenience methods.
Current state
lib/std/collections.w contains the core collection types and only a small set of iterator adapters. The declared adapter structs include MapIter, FilterIter, TakeIter, ZipIter, and FlatMapIter at lib/std/collections.w:113-131, and the Vec iterator implementation begins at lib/std/collections.w:133. The required tier-1 operation set is not present as a generic stdlib surface.
test/spec/spec_ss13_3_collection_operations.w covers the currently implemented subset such as map, filter, take, zip, flat_map, fold, and collect[Vec]. It does not cover most operations listed above, map/set collection targets, or HashMap convenience methods.
docs/completed/spec-impl-unalignment.md:262 records that collect[C]() is currently Vec-only relative to the spec.
Implementation plan
- Resolve the generic-instantiation blocker first so adapter types can be implemented once and reused across element types.
- Define the core adapter structs and
Iterimpls inlib/std/collections.w, starting with operations that other spec features desugar through:collect[C],filter_map,enumerate,chain,zip_with,partition, andunzip. - Implement eager consumers as generic functions or methods with clear trait bounds rather than hardcoded type branches.
- Add standalone constructors under the
Iternamespace or the local equivalent chosen by the existing stdlib naming pattern. - Implement HashMap convenience methods after the map entry API and collection-target story are stable.
- Keep adapter state explicit and Copy/move behavior compatible with existing iterator borrowing rules.
Test plan
Expand test/spec/spec_ss13_3_collection_operations.w into focused sections for transformations, consumers, constructors, and HashMap conveniences. Add compile-error tests for missing trait bounds or incompatible target types. Add behavior tests for laziness where visible, especially take, drop, take_while, drop_while, peekable, scan, and infinite constructors such as repeat.
Acceptance criteria
- Every operation listed in §13.3 has a stdlib implementation or a loud compile-time diagnostic explaining an unsupported target.
- Existing pipeline tests still pass.
- New tests cover both common success cases and at least one type-bound failure per operation family.
- Comprehensions and collection literals can reuse the same
collect[C]target path instead of maintaining separate collection-building logic.
Dependencies
Depends on #391 for the TY_GENERIC_INST fix. Also feeds #388 and #390 because target-polymorphic collect[C]() and comprehensions need this generic collection surface.
Activity
ehartford commentedon Jun 15, 2026
Implemented in 122e295. Added lazy iterator adapters and codegen for filter_map, drop, take_while, drop_while, enumerate, chain, zip_with, and step_by; added eager consumers for product, min/max, min_by/max_by, find, position, any/all/none, for_each, and unzip; expanded §13.3 spec coverage; and added loud diagnostics for still-unsupported §13.3 iterator operations and Iter constructors. HashMap convenience coverage remains green in the existing §13.3 spec test. Verification passed with the project seed: build, fixpoint, full test suite, and test-green.