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

possible Enumerable/Iterable .map bug #1199

Closed
technorama opened this issue Aug 16, 2015 · 5 comments
Closed

possible Enumerable/Iterable .map bug #1199

technorama opened this issue Aug 16, 2015 · 5 comments

Comments

@technorama
Copy link
Contributor

When map is used the expected Enumerable type is incorrect. The bug seems to appear with any tuple types.

class A
# why doesn't this work?
  include Enumerable({Int32, String})

# but this does???
#  include Enumerable(Int32)

  def each
    yield 1, "foo"
    yield 3, "bar"
  end
end

a = A.new
a.each do |k, v|
  puts "#{k} #{v} #{typeof(k)} "
end
p a.map { |k, v| "foo" }

The same code also failed with Iterable/Iterator.
http://carc.in/#/r/bkv

@asterite
Copy link
Member

It's because yielding multiple values doesn't mean yielding a tuple of those values. I don't consider this a bug.

Also check this: #105 (comment)

So I think this is a duplicate of #105, but please reopen if not

@waterlink
Copy link
Contributor

BTW, Working version of provided code example: http://carc.in/#/r/bww

Best Regards,
Alexey Fedorov,
Sr Ruby, Clojure, Crystal, Golang Developer,
Microservices Backend Engineer,
+49 15757 486 476

2015-08-19 0:58 GMT+02:00 Ary Borenszweig notifications@github.com:

It's because yielding multiple values doesn't mean yielding a tuple of
those values. I don't consider this a bug.

Also check this: #105 (comment)
#105 (comment)

So I think this is a duplicate of #105
#105, but please reopen if
not


Reply to this email directly or view it on GitHub
#1199 (comment).

@jhass
Copy link
Member

jhass commented Aug 18, 2015

Instead of Tuple.new(1, "foo") you can just write {1, "foo"} though.

@alex-fedorov
Copy link

@jhass yeah: http://carc.in/#/r/bwx Though parenthesis for yield are required in this case (so that parser does not confuse it with block)

@technorama
Copy link
Contributor Author

I would like yield(a, b) to work with Enumerable AND map { |a, b| }.
No solution provided works so far.

This issue similar but not identical to #105. The issue here is with Enumerable and the types that it accepts. I would like yield(a, b) to work with Enumerable AND map { |a, b| }.

  1. yield(a, b) is not a tuple
  2. yield({a, b}) yields a single tuple to a block in map
  • include Enumerable({a, b}) works, but map { |a, b| } doesn't work
  • include Enumerable(a, b) is not possible

Possible solutions:

  • Make Enumerable(a, b) work with multiple values (non-tuple)
  • Make yield(a, b) a tuple and automatically destructure in the block
  • Other?

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

No branches or pull requests

5 participants