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

Proposal: peekable iterator and pattern matching on iterators #991

Open
glyh opened this issue Sep 13, 2024 · 2 comments
Open

Proposal: peekable iterator and pattern matching on iterators #991

glyh opened this issue Sep 13, 2024 · 2 comments

Comments

@glyh
Copy link

glyh commented Sep 13, 2024

For now there's no way to match on iteraters the same way we do with Lists, and I reckon it would be useful as it can drastically simplify the way people work with iterators.

So ideally it would be something like this:

match [1,2,3].iter() {
  1 ~> 2 ~> rest {
    // rest is a iterator here. 
  }
  End {
  }
}
@glyh
Copy link
Author

glyh commented Sep 13, 2024

I am aware that this is a performance penalty as bascially we need to store what the underlying algorithm produces to make an iterator peekable. But still, I would argue this provides a unified iterface across data structures.

We can have some other data structures and retain the original iterator, so if user want a fast implementation, they choose Iter, and if they want something more fancy, they can choose PatIter

@Guest0x0
Copy link
Contributor

Indeed an external iterator implementation would be very handy. I suggest starting with a prototype package on https://mooncakes.io, and if it turns out useful enough, we may consider moving it to moonbitlang/xor moonbitlang/core, and add pattern match support to it.

related: #994

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