Skip to content

Tier-1 collection operations as With generics (§13.3) #392

Closed

Description

@ehartford

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

  1. Resolve the generic-instantiation blocker first so adapter types can be implemented once and reused across element types.
  2. Define the core adapter structs and Iter impls in lib/std/collections.w, starting with operations that other spec features desugar through: collect[C], filter_map, enumerate, chain, zip_with, partition, and unzip.
  3. Implement eager consumers as generic functions or methods with clear trait bounds rather than hardcoded type branches.
  4. Add standalone constructors under the Iter namespace or the local equivalent chosen by the existing stdlib naming pattern.
  5. Implement HashMap convenience methods after the map entry API and collection-target story are stable.
  6. 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

  1. ehartford commented on Jun 15, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions