Skip to content

D142: a range on the left of a pipeline does not iterate (no iter() on Range[T]) #2544

Closed

Description

@ehartford

D142 (§13.5) rules that a sequence on the left of |> iterates by the rule for uses. A range is a sequence for iterates, but it has no .iter() method, which is what the implemented rule looks for:

fn main:
    let a = (0..10) |> map(it * 2) |> filter(it > 4) |> collect[List]()
    print(f"{a.len()}")

v0.15.3.0-g5e0bd9076: error: undefined variable at it (the stage sees no iterator); (0..10).map(it * 2) says unknown method 'map' for type 'Range[isize]'.

Expected: the pipeline iterates the range, as for i in 0..10 does. The same shape as a slice's iter() (D142): a std RangeIter[T] over the range with an Iter[T] impl, and Sema dispatching r.iter(), for (kept on the built-in counter loop) and |> over a Range[T] to it. A gen fn's value in a pipeline is a separate question: for x in g is g.each(body) (D69), push-based, so g |> map(..) needs an adapter over each or a ruling that generators are consumed by for only.

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