Skip to content

Iterating over finite spaces #29

Open
@wschella

Description

@wschella

Hi!

Recently I came to the conclusion that using the FiniteSpace trait in a generic way (when building other traits and abstractions) is quite unwieldy. I think boils down to the range() function being at the same time not powerful enough, and quite strict due to the return type of ::std::ops::Range.

  1. You can't implement Range<CustomType>, making it hard to implement Space for a custom type (i.e. an enum).
  2. Range<T> does not imply Range<T>: Iterator<Item = T>, requiring the need to specify this bound yourself, which is usually quite awkward. E.g.: Range<State<Self>>: Iterator<Item = State<Self>>. If this is in a trait, it also requires all implementors to copy this. Iterating comfortably over all values in a space seems like quite useful for a finite space.

So I would propose doing something like this:

pub trait FiniteSpace: Space {
    type Iter: Iterator<Item = Self::Value>;

    fn iter(&self) -> Self::Iter;
}

Would you be interested in receiving PR from me applying this change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions