Skip to content

iter module and ranges #2715

Closed
Closed
@jesse99

Description

@jesse99

The iter module has lots of handy stuff, but afaict there's no built-in way to iterate over numeric ranges. One thing that would be helpful is if, uint at least, had an impl something like

impl of iter::base_iter<uint> for uint
{
    fn each(blk: fn(&&uint) -> bool)
    {
        let mut i = 0u;
        while i < self
        {
            if (!blk(i))
            {
                ret;
            }
            i += 1u;
        }
    }

    fn size_hint() -> option<uint>
    {
        option::some(self)
    }
}

Even better would be a real range type. They seem to be a nice abstraction for collections and algorithms and they would make it simpler to iterate over ranges with non-zero lower bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions