Skip to content

Commit

Permalink
Merge pull request #474 from ruby/enumerable
Browse files Browse the repository at this point in the history
Drop second type parameter of `Enumerable` and `_Each`
  • Loading branch information
soutaro committed Nov 13, 2020
2 parents c76f0b7 + 92fafc9 commit 219bd9c
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module ChatApp
def initialize: (name: String) -> void
def each_member: () { (User | Bot) -> void } -> void # `{` and `}` means block.
| () -> Enumerable[User | Bot, void] # Method can be overloaded.
| () -> Enumerator[User | Bot, void] # Method can be overloaded.
end
end
```
Expand Down
2 changes: 1 addition & 1 deletion core/array.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
# for pack.c
#
class Array[unchecked out Elem] < Object
include Enumerable[Elem, self]
include Enumerable[Elem]

# Returns a new array.
#
Expand Down
4 changes: 2 additions & 2 deletions core/builtin.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface _ToPath
def to_path: () -> String
end

interface _Each[out A, out B]
def each: { (A) -> void } -> B
interface _Each[out A]
def each: { (A) -> void } -> void
end

interface _Reader
Expand Down
2 changes: 1 addition & 1 deletion core/dir.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# itself (`.`).
#
class Dir
include Enumerable[String, Dir]
include Enumerable[String]

# Returns a new directory object for the named directory.
#
Expand Down
66 changes: 33 additions & 33 deletions core/enumerable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# objects in the collection must also implement a meaningful `<=>`
# operator, as these methods rely on an ordering between members of the
# collection.
module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
module Enumerable[unchecked out Elem]: _Each[Elem]
# Passes each element of the collection to the given block. The method
# returns `true` if the block never returns `false` or `nil` . If the
# block is not given, Ruby adds an implicit block of `{ |obj| obj }` which
Expand Down Expand Up @@ -66,24 +66,24 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| () { (Elem) -> boolish } -> Integer

def cycle: (?Integer n) { (Elem arg0) -> untyped } -> NilClass
| (?Integer n) -> ::Enumerator[Elem, Return]
| (?Integer n) -> ::Enumerator[Elem, NilClass]

def detect: (?Proc ifnone) { (Elem) -> boolish } -> Elem?
| (?Proc ifnone) -> ::Enumerator[Elem, Return]
| (?Proc ifnone) -> ::Enumerator[Elem, Elem?]

def drop: (Integer n) -> ::Array[Elem]

def drop_while: () { (Elem) -> boolish } -> ::Array[Elem]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

def each_cons: (Integer n) { (::Array[Elem] arg0) -> untyped } -> NilClass
| (Integer n) -> ::Enumerator[::Array[Elem], Return]
| (Integer n) -> ::Enumerator[::Array[Elem], NilClass]

def each_with_index: () { (Elem arg0, Integer arg1) -> untyped } -> ::Enumerable[Elem, Return]
| () -> ::Enumerator[[ Elem, Integer ], Return]
def each_with_index: () { (Elem arg0, Integer arg1) -> untyped } -> void
| () -> ::Enumerator[[ Elem, Integer ], void]

def each_with_object: [U] (U arg0) { (Elem arg0, untyped arg1) -> untyped } -> U
| [U] (U arg0) -> ::Enumerator[[ Elem, U ], Return]
| [U] (U arg0) -> ::Enumerator[[ Elem, U ], U]

# Returns an array containing the items in *enum* .
#
Expand All @@ -97,14 +97,14 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
def entries: () -> ::Array[Elem]

def find_all: () { (Elem) -> boolish } -> ::Array[Elem]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

alias select find_all
alias filter find_all

def find_index: (?untyped value) -> Integer?
| () { (Elem) -> boolish } -> Integer?
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, Integer?]

# Returns the first element, or the first `n` elements, of the enumerable.
# If the enumerable is empty, the first form returns `nil`, and the
Expand All @@ -127,7 +127,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U]

def group_by: [U] () { (Elem arg0) -> U } -> ::Hash[U, ::Array[Elem]]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

def `include?`: (untyped arg0) -> bool

Expand Down Expand Up @@ -160,9 +160,9 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| (Integer arg0) -> ::Array[Elem]
| (Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]

def max_by: () -> ::Enumerator[Elem, Return]
def max_by: () -> ::Enumerator[Elem, Elem?]
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
| (Integer arg0) -> ::Enumerator[Elem, Return]
| (Integer arg0) -> ::Enumerator[Elem, ::Array[Elem]]
| (Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]

# Returns the object in *enum* with the minimum value. The first form
Expand All @@ -189,9 +189,9 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| (Integer arg0) -> ::Array[Elem]
| (Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]

def min_by: () -> ::Enumerator[Elem, Return]
def min_by: () -> ::Enumerator[Elem, Elem?]
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> Elem?
| (Integer arg0) -> ::Enumerator[Elem, Return]
| (Integer arg0) -> ::Enumerator[Elem, ::Array[Elem]]
| (Integer arg0) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]

# Returns a two element array which contains the minimum and the maximum
Expand All @@ -207,7 +207,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| () { (Elem arg0, Elem arg1) -> Integer } -> [ Elem?, Elem? ]

def minmax_by: () -> [ Elem?, Elem? ]
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Enumerator[Elem, Return]
| () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> [ Elem?, Elem? ]

# Passes each element of the collection to the given block. The method
# returns `true` if the block never returns `true` for all elements. If
Expand Down Expand Up @@ -252,13 +252,13 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| () { (Elem) -> boolish } -> bool

def partition: () { (Elem) -> boolish } -> [ ::Array[Elem], ::Array[Elem] ]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, [ ::Array[Elem], ::Array[Elem] ]]

def reject: () { (Elem) -> boolish } -> ::Array[Elem]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

def reverse_each: () { (Elem arg0) -> untyped } -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, Return]
def reverse_each: () { (Elem arg0) -> untyped } -> void
| () -> ::Enumerator[Elem, void]

# Returns an array containing the items in *enum* sorted.
#
Expand All @@ -284,12 +284,12 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| () { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem]

def sort_by: () { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

def take: (Integer n) -> ::Array[Elem]?

def take_while: () { (Elem) -> boolish } -> ::Array[Elem]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[Elem]]

# Implemented in C++
# Returns the result of interpreting *enum* as a list of `[key, value]`
Expand All @@ -309,7 +309,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| [T, U] () { (Elem) -> [T, U] } -> ::Hash[T, U]

def each_slice: (Integer n) { (::Array[Elem]) -> untyped } -> NilClass
| (Integer n) -> ::Enumerator[::Array[Elem], Return]
| (Integer n) -> ::Enumerator[::Array[Elem], NilClass]

interface _NotFound[T]
def call: () -> T
Expand All @@ -320,8 +320,8 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| [T] (_NotFound[T] ifnone) { (Elem) -> boolish } -> (Elem | T)
| [T] (_NotFound[T] ifnone) -> ::Enumerator[Elem, Elem | T]

def flat_map: [U] () { (Elem arg0) -> U } -> U
| () -> ::Enumerator[Elem, Return]
def flat_map: [U] () { (Elem) -> (Array[U] | U) } -> Array[U]
| () -> ::Enumerator[Elem, Array[untyped]]

def map: [U] () { (Elem arg0) -> U } -> ::Array[U]
| () -> ::Enumerator[Elem, ::Array[untyped]]
Expand Down Expand Up @@ -371,7 +371,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
# # show pythagorean triples less than 100
# p pythagorean_triples.take_while { |*, z| z < 100 }.force
# ```
def lazy: () -> Enumerator::Lazy[Elem, Return]
def lazy: () -> Enumerator::Lazy[Elem, void]

def uniq: () -> ::Array[Elem]
| () { (Elem item) -> untyped } -> ::Array[Elem]
Expand All @@ -382,22 +382,22 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
| [U] (?U arg0) { (Elem arg0) -> U } -> U

def filter_map: [U] () { (Elem elem) -> (nil | false | U) } -> ::Array[U]
| () -> ::Enumerator[Elem, Return]
| () -> ::Enumerator[Elem, ::Array[untyped]]

def chain: (*self enumerables) -> ::Enumerator::Chain[Elem, ::Array[self]]
def chain: (*self enumerables) -> ::Enumerator::Chain[Elem]

def tally: () -> ::Hash[Elem, Integer]

def each_entry: () -> ::Enumerator[Elem, Return]
def each_entry: () -> ::Enumerator[Elem, self]
| () { (Elem arg0) -> untyped } -> self

# variadic type parameter is not supported yet
# https://github.com/ruby/rbs/issues/21
def zip: [Elem2, Return2] (::Enumerable[Elem2, Return2] enum) -> ::Array[[Elem, Elem2 | nil]]
| [U, Elem2, Return2] (::Enumerable[Elem2, Return2]) { ([Elem, Elem2 | nil]) -> U } -> nil
def zip: [Elem2] (::Enumerable[Elem2] enum) -> ::Array[[Elem, Elem2 | nil]]
| [U, Elem2] (::Enumerable[Elem2]) { ([Elem, Elem2 | nil]) -> U } -> nil

def chunk: () -> ::Enumerator[Elem, Return]
| [U] () { (Elem elt) -> U } -> ::Enumerator[[U, Array[Elem]], void]
def chunk: [U] () { (Elem elt) -> U } -> ::Enumerator[[U, Array[Elem]], void]
| () -> ::Enumerator[Elem, Enumerator[untyped, untyped]]

def chunk_while: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]

Expand Down
10 changes: 5 additions & 5 deletions core/enumerator.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
# # => [], [:b], [1], [:b, 1], [1, 2], [:b, 1, 2], 3
# ```
class Enumerator[unchecked out Elem, out Return] < Object
include Enumerable[Elem, Return]
include Enumerable[Elem]

def each: () { (Elem arg0) -> untyped } -> Return
| () -> self
Expand Down Expand Up @@ -242,8 +242,8 @@ class Enumerator[unchecked out Elem, out Return] < Object
| [U] (U arg0) -> ::Enumerator[[ Elem, U ], Return]
end

class Enumerator::Generator[out Elem, out Return] < Object
include Enumerable[Elem, Return]
class Enumerator::Generator[out Elem] < Object
include Enumerable[Elem]
end

class Enumerator::Lazy[out Elem, out Return] < Enumerator[Elem, Return]
Expand All @@ -257,6 +257,6 @@ class Enumerator::Yielder < Object
def to_proc: () -> Proc
end

class Enumerator::Chain[out Elem, out Return] < Object
include Enumerable[Elem, Return]
class Enumerator::Chain[out Elem] < Object
include Enumerable[Elem]
end
2 changes: 1 addition & 1 deletion core/hash.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
# See also Object#hash and Object#eql?
#
class Hash[unchecked out K, unchecked out V] < Object
include Enumerable[[K, V], Hash[K, V]]
include Enumerable[[K, V]]

# Creates a new hash populated with the given objects.
#
Expand Down
2 changes: 1 addition & 1 deletion core/io.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
class IO < Object
include File::Constants

include Enumerable[String, IO]
include Enumerable[String]

def <<: (untyped arg0) -> self

Expand Down
2 changes: 1 addition & 1 deletion core/range.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
# r.member?(Xs.new(5)) #=> true
# ```
class Range[out Elem] < Object
include Enumerable[Elem, Range[Elem]]
include Enumerable[Elem]

def ==: (untyped obj) -> bool

Expand Down
2 changes: 1 addition & 1 deletion core/struct.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# struct member which is either a quoted string ( `"name"` ) or a
# [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
class Struct[Elem] < Object
include Enumerable[Elem, Struct[Elem]]
include Enumerable[Elem]

type attribute_name = Symbol | String

Expand Down
6 changes: 3 additions & 3 deletions stdlib/csv/0/csv.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
# with it.
#
class CSV < Object
include Enumerable[untyped, untyped]
include Enumerable[untyped]

# This method is intended as the primary interface for reading CSV files. You
# pass a `path` and any `options` you wish to set for the read. Each row of file
Expand Down Expand Up @@ -407,7 +407,7 @@ CSV::VERSION: String
# processing is activated.
#
class CSV::Row < Object
include Enumerable[untyped, untyped]
include Enumerable[untyped]

# If a two-element Array is provided, it is assumed to be a header and field and
# the pair is appended. A Hash works the same way with the key being the header
Expand Down Expand Up @@ -578,7 +578,7 @@ end
# processing is activated.
#
class CSV::Table[out Elem] < Object
include Enumerable[untyped, untyped]
include Enumerable[untyped]

# Constructs a new CSV::Table from `array_of_rows`, which are expected to be
# CSV::Row objects. All rows are assumed to have the same headers.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/dbm/0/dbm.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# puts db['822']
#
class DBM
include Enumerable[untyped, untyped]
include Enumerable[untyped]

# Open a dbm database and yields it if a block is given. See also `DBM.new`.
#
Expand Down
2 changes: 1 addition & 1 deletion stdlib/prime/0/prime.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Prime
class PseudoPrimeGenerator
def initialize: (?Integer?) -> void

include Enumerable[Integer, void]
include Enumerable[Integer]

attr_accessor upper_bound (): Integer?

Expand Down
Loading

0 comments on commit 219bd9c

Please sign in to comment.