core/enumerable.rbs in rbs-0.16.0 vs core/enumerable.rbs in rbs-0.17.0

- old
+ new

@@ -3,11 +3,11 @@ # must provide a method `each`, which yields successive members of the # collection. If `Enumerable#max`, `#min`, or `#sort` is used, the # 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 # will cause [all?](Enumerable.downloaded.ruby_doc#method-i-all-3F) to # return `true` when none of the collection members are `false` or `nil` . @@ -64,28 +64,28 @@ def count: () -> Integer | (?untyped) -> Integer | () { (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* . # # ```ruby # (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] @@ -95,18 +95,18 @@ # Prime.entries 10 #=> [2, 3, 5, 7] # ``` 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 # second form returns an empty array. # @@ -116,20 +116,20 @@ # %w[foo bar baz].first(10) #=> ["foo", "bar", "baz"] # [].first #=> nil # [].first(10) #=> [] # ``` def first: () -> Elem? - | (?Integer n) -> ::Array[Elem]? + | (Integer n) -> ::Array[Elem]? def grep: (untyped arg0) -> ::Array[Elem] | [U] (untyped arg0) { (Elem arg0) -> U } -> ::Array[U] def grep_v: (untyped arg0) -> ::Array[Integer] | [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 def inject: (untyped init, Symbol method) -> untyped | (Symbol method) -> untyped @@ -155,17 +155,17 @@ # a.max(2) {|a, b| a.length <=> b.length } #=> ["albatross", "horse"] # [5, 1, 3, 4, 2].max(3) #=> [5, 4, 3] # ``` def max: () -> Elem? | () { (Elem arg0, Elem arg1) -> Integer } -> Elem? - | (?Integer arg0) -> ::Array[Elem] - | (?Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem] + | (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) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem] + | (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 # assumes all objects implement `Comparable` ; the second uses the block # to return *a \<=\> b* . # @@ -184,17 +184,17 @@ # a.min(2) {|a, b| a.length <=> b.length } #=> ["dog", "horse"] # [5, 1, 3, 4, 2].min(3) #=> [1, 2, 3] # ``` def min: () -> Elem? | () { (Elem arg0, Elem arg1) -> Integer } -> Elem? - | (?Integer arg0) -> ::Array[Elem] - | (?Integer arg0) { (Elem arg0, Elem arg1) -> Integer } -> ::Array[Elem] + | (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) { (Elem arg0) -> (Comparable | ::Array[untyped]) } -> ::Array[Elem] + | (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 # value in the enumerable. The first form assumes all objects implement # `Comparable` ; the second uses the block to return *a \<=\> b* . # @@ -205,11 +205,11 @@ # ``` def minmax: () -> [ Elem?, Elem? ] | () { (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 # the block is not given, `none?` will return `true` only if none of the # collection members is true. @@ -250,17 +250,17 @@ # ``` def one?: () -> bool | () { (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. # # Comparisons for the sort will be done using the items’ own `<=>` # operator or using an optional code block. @@ -282,16 +282,16 @@ # computation or comparison is expensive. def sort: () -> ::Array[Elem] | () { (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]` # pairs. # @@ -304,25 +304,26 @@ # ```ruby # (1..5).to_h {|x| [x, x ** 2]} # #=> {1=>1, 2=>4, 3=>9, 4=>16, 5=>25} # ``` def to_h: () -> ::Hash[untyped, untyped] + | [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 end def find: () { (Elem) -> boolish } -> Elem? | () -> ::Enumerator[Elem, Elem?] | [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]] def member?: (untyped arg0) -> bool @@ -368,36 +369,36 @@ # p pythagorean_triples.take(10).force # take is lazy, so force is needed # p pythagorean_triples.first(10) # first is eager # # 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] def sum: () -> (Elem | Integer) | [T] () { (Elem arg0) -> T } -> (Integer | T) | [T] (?T arg0) -> (Elem | T) | [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] def slice_when: () { (Elem elt_before, Elem elt_after) -> boolish } -> ::Enumerator[::Array[Elem], void]