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

Add Enumerator::_Each interface #1915

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

ParadoxV5
Copy link
Contributor

@ParadoxV5 ParadoxV5 commented Jun 29, 2024

It is a common pattern for #each to support both yielding to a block and returning an Enumerator when no block given.
I add this interface as a convenience for library classes; it is not a replacement for ::_Each, which does not require no-block support.

soutaro just for clarity, I'm not arguing for a revision of the existing one, but to add a new one. The reasoning is, the current _Each already describes the requirement for implementing a class decorated with Enumerable. But an _EnumEach is common enough (IMO) to warrant defining it as a common interface (as most core and stdlib enumerables already do it).
#424 (comment)

I put this interface under the Enumerator namespace to represent how it’s a “special” edition.
Regarding why I’m sticking with _Each:

I think _MethodName should be restricted to interfaces that implement that method_name minimally.
[…]
If you want to specify that your class implements each "correctly", then yes, you should have these two interfaces and a shorthand might be useful.
#424 (comment)

  • Resolves _EnumEach interface #424
    • more like – necroposts it 😁
    • Feel free to continue discussing the design in the issue and leave just the technical details here.

@sampersand
Copy link
Contributor

I approve! Not only do I agree, I think we should think about changing Enumerable to have it as a prerequisite.

@ParadoxV5
Copy link
Contributor Author

ParadoxV5 commented Jul 5, 2024

I think we should think about changing Enumerable to have it as a prerequisite.

Enumerable technically does not require the #each to have a no-block branch at all.
Although it would be an easy oversight to assume the no-block branch exists from any ordinary Enumerable (I may have fallen into this trap before).

@soutaro soutaro added this to the RBS 3.6 milestone Jul 25, 2024
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙆‍♂️

@soutaro soutaro added this pull request to the merge queue Jul 25, 2024
Merged via the queue into ruby:master with commit 22e9be4 Jul 25, 2024
19 checks passed
@ParadoxV5 ParadoxV5 deleted the 424-enum-each branch September 13, 2024 19:44
@soutaro soutaro added the Released PRs already included in the released version label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

_EnumEach interface
3 participants