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

core: Add Enumerator.produce #1516

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Sep 11, 2023

Add the signature for Enumerator.produce
https://bugs.ruby-lang.org/issues/14781

@tk0miya tk0miya force-pushed the stdlib/Enumerator.produce branch 2 times, most recently from f3acb2a to 2ee4404 Compare September 11, 2023 17:53
@@ -124,6 +124,43 @@
class Enumerator[unchecked out Elem, out Return] < Object
include Enumerable[Elem]

# <!--
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this document from enumerator.c. Is that alright?
https://github.com/ruby/ruby/blob/master/enumerator.c#L3052-L3086

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this comment by the result of CI (rake annotate?): https://github.com/ruby/rbs/actions/runs/6149970207/job/16686945264?pr=1516

# PATTERN = %r{\d+|[-/+*]}
# Enumerator.produce { scanner.scan(PATTERN) }.slice_after { scanner.eos? }.first
# # => ["7", "+", "38", "/", "6"]
def self.produce: (?untyped initial) { (untyped prev) -> untyped } -> self
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first, I thought it would be better to use a type parameter for this method (ex. [T] (T initial) { (T prev) -> T } -> self[T, untyped]).
But developers can use the different types between initial and prev (the return type of the block). So it's difficult to give a better type to this method to me. Therefore, I used untyped for this.

@tk0miya tk0miya force-pushed the stdlib/Enumerator.produce branch 3 times, most recently from 638717a to d862f19 Compare September 11, 2023 18:36
core/enumerator.rbs Outdated Show resolved Hide resolved
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.

Thank you, @tk0miya and @ParadoxV5 ! 🎉

tk0miya and others added 2 commits September 28, 2023 16:54
Co-authored-by: Jimmy H <paradox.ver5@gmail.com>
Because the `#each` call never returns.
@soutaro soutaro added this pull request to the merge queue Sep 28, 2023
Merged via the queue into ruby:master with commit 5f992e6 Sep 28, 2023
23 checks passed
@tk0miya tk0miya deleted the stdlib/Enumerator.produce branch September 30, 2023 07:53
@soutaro soutaro added this to the RBS 3.3 milestone Oct 31, 2023
@soutaro soutaro added the Released PRs already included in the released version label Oct 31, 2023
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.

3 participants