ruby/typeprof

Special handling for Array#zip

mame opened this issue · 0 comments

mame commented

It is useful to keep the elements of Array#zip as tuples. RBS of Array#zip has less information for the behavior, so it would be good to implement it as a built-in method.

as = [1, 2, 3]
bs = %w(a b c)

p as.zip(bs)
#=> expected: Array[[Integer, String]] (or [Integer, String?])
#   actual:   Array[Array[(Integer | String)?]]

as.zip(bs) do |a, b|
  p a #=> expected: Integer
      #   actual: (Integer | String)?
  p b #=> expected: String (or String?)
      #   actual: (Integer | String)?
end

cs = [1.0, 2.0, 3.0]

as.zip(bs, cs) do |a, b, c|
  p a #=> expected: Integer
      #   actual: untyped
  p b #=> expected: String (or String?)
      #   actual: untyped
  p c #=> expected: Float (or Float?)
      #   actual: untyped
end