From: Nathan Broadbent Date: 2012-11-01T19:05:51+09:00 Subject: [ruby-core:48700] Re: [ruby-trunk - Feature #7241] Enumerable#to_h proposal --e89a8f643544ddb48704cd6c2957 Content-Type: text/plain; charset=ISO-8859-1 > > I wouldn't say it is over. See #4151. ... Is #each_with a better name? > Has anyone suggested `map_to`? I think `map_to` has a clearer intention than `each_with`, because you're mapping the collection onto something, and then returning it. I don't really like the `each` part of `each_with_object`, because `array.each` just returns the array. Since we usually use `each` to iterate, and `map` to build an array, I think `map_to()` might make sense. How does this look: [1, 2, 3].map_to({}) { |e, hash| hash[e] = e ** 2 } I'd also propose a `map_to_hash` method. It's longer than `map_to({})`, but I think it's nicer to read: [1, 2, 3].map_to_hash { |e, hash| hash[e] = e ** 2 } `map_to_hash(0)` would also be nicer than `map_to(Hash.new(0))`. What do you think? --e89a8f643544ddb48704cd6c2957 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I wouldn't sa= y it is over. See #4151. =A0 ...=A0
Is #each_with a better name?

Has anyone= suggested `map_to`? I think `map_to` has a clearer intention than `each_wi= th`, because you're mapping the collection onto something, and then ret= urning it.
I don't really like the `each` part of `each_with_object`, because= `array.each` just returns the array. Since we usually use `each` to iterat= e, and `map` to build an array, I think `map_to(<object>)` might make= sense.

How does this look:

=A0 [1, 2,= 3].map_to({}) { |e, hash| hash[e] =3D e ** 2 }

I'd also propose a `map_to_hash` method. It's longer t= han `map_to({})`, but I think it's nicer to read:

=A0 [1, 2, 3].map_to_hash { |e, hash| hash[e] =3D e ** = 2 }


`map_to_hash(0)` would also be = nicer than `map_to(Hash.new(0))`.


What do you think?
--e89a8f643544ddb48704cd6c2957--