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

Enumerator#initialize support nil, #call and #to_int #1904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented Jun 21, 2024

Argument of Enumerator#initialize allows nil, #call and #to_int object.
Included Float::INFINITY in #to_int.

https://github.com/ruby/ruby/blob/ac9e84df3d0b06e62498aafbca99e8f8475ec142/enumerator.c#L437-L451

@ksss ksss changed the title [Enumerator#initialize] support nil, #call and #to_int Enumerator#initialize support nil, #call and #to_int Jun 21, 2024
@@ -293,7 +297,7 @@ class Enumerator[unchecked out Elem, out Return] < Object
# lazy fashion (see Enumerator#size). It can either be a value or a callable
# object.
#
def initialize: (?Integer arg0) { (Enumerator::Yielder arg0) -> Return } -> void
def initialize: (?(nil | _Call | ::_ToInt) arg0) { (Enumerator::Yielder arg0) -> Return } -> void
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def initialize: (?(nil | _Call | ::_ToInt) arg0) { (Enumerator::Yielder arg0) -> Return } -> void
def initialize: (?(int? | _Call) size) { (Yielder yielder) -> Return } -> void

Comment on lines +272 to +274
interface _Call
def call: () -> untyped
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Enumerator.new(->{'hi'}) {}.size #=> "hi"
Suggested change
interface _Call
def call: () -> untyped
end
interface _Size
def call: () -> (Integer | Float)?
end

Relevant: #420 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants