-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[WIP] Implement ruby-style Enumerator #6385
base: master
Are you sure you want to change the base?
Conversation
If you turn |
Also, I'd really really rather not call it an enumerator. Given my java/C# experience |
I agree that having both I've spend quite some time thinking about this and I think it's the wrong level of abstraction.
I'll update #6357 with a more detailed analysis once I've fully thought it through. |
1e7ec8f
to
ff6003f
Compare
For me Enumerator is fine. It's also called like that in Ruby.. |
Yes, but Ruby does not have an |
But Java does. |
@asterite but Enumerator in C# is very similar to Iterator in Crystal. That's the confusion. The naming doesn't really matter anyway, since we can probably make the interface just |
That's what I thought, but no, because you always have to specify the generic type. But maybe Iterator::Something(T) could work. I'm still not 100% convinced about the implementation, I feel like something is missing. |
I'm not too happy about the changes to Fiber that the current implementation requires – it seems overkill. I think I'll explore an alternate approach of raising an exception inside the yielder block. |
Btw. I also noticed that we are currently lacking exception bubbling from the yielder block to the wrapping enumerator, because exceptions in fibers are silently swallowed. I've already implemented that locally by rescuing from exceptions in the fiber block and assigning it to an instance variable on the enumerator. The exception will then be re-raised in I'll add it to the WIP implementation along with specs in the next iteration. |
run | ||
end | ||
|
||
# Returns the next element yielded from the block or `Iterator::Stop::INSTANCE` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an Enumerator should the return type be an Enumerator::Stop
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it, but since the Iterator
module is included it probably already works with both Enumerator::Stop
and Iterator::Stop
.
This is a work-in-progress and shouldn't be merged yet!
I'll update the description of the PR once the details are fully flushed out.
For discussion see #6357.
A big thanks to @asterite who helped in implementing most of the fiber stuff.