Proposal: peekable iterator and pattern matching on iterators
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 {
}
}
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
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
Closing as this requires an implementation of external iterator