Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator interface on IntervalSet #222

Open
ahjulstad opened this issue Oct 17, 2023 · 1 comment
Open

Iterator interface on IntervalSet #222

ahjulstad opened this issue Oct 17, 2023 · 1 comment

Comments

@ahjulstad
Copy link

Any reason not to implement the iterator interface on the intervalset?

I wanted to do things like

sum( (span(s) for s in u) )

but that doesn't work, I need to explicitly convert like this using

sum( (span(s) for s in convert(Array, u)) )

As the convert function is intended to be called implicitly; it should still be the same data, it feels like u and convert(Array, u) should be very similar, but it doesn't.

The following three lines is all the is needed. Does it make sense to add?

Base.IteratorSize(i::Intervals.IntervalSet) = Base.SizeUnknown()
Base.iterate(i::Intervals.IntervalSet) = Base.iterate(i.items)
Base.iterate(i::Intervals.IntervalSet, state) = Base.iterate(i.items, state)
@bjarthur
Copy link

bjarthur commented Jan 2, 2024

@ahjulstad maybe submitting a PR will get the dev's attention. i'd find such an iterator very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants