From: Matthew Kerwin Date: 2012-11-13T20:37:18+09:00 Subject: [ruby-core:49297] Re: [ruby-trunk - Feature #7340] 'each_with' or 'into' alias for 'each_with_object' --047d7b10d185158dcc04ce5ed7a1 Content-Type: text/plain; charset=ISO-8859-1 On 13 November 2012 21:25, rosenfeld (Rodrigo Rosenfeld Rosas) < rr.rosas@gmail.com> wrote: > > Issue #7340 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas). > > > The reason I dislike each_with_object and each_with is the "each" on them. > "each"'s return value isn't meaningful to me. That's why I would prefer > "map_to", "map_into" or just "into". > > "into" here doesn't mean putting values "into" the array or hash. It > means: "turn/map object into a hash/array/whatever". It is not about > putting something into the passed object, but about converting the original > object (say numbers) into the object being passed as the initial value like > a hash or an array. > > It is ok to chain operations as a pattern (like the one used by jQuery) so > that an_array.each{...}.sort would justify "each" returning the original > "an_array", but only to be able to chain operations and not because "each" > implies returning anything meaningful. > > In that sense, each_with_object is currently supposed to return some > meaningful value. That is why I'd prefer to call it "map_to", "map_into" or > just "into". > > numbers.map_into({}){...} should read "map numbers into a hash where ...". > It would be even shorter if we just abbreviated "map_into" as just "into". > > Also, if there is any chance that this wouldn't be an alias to > each_with_object, I'd prefer the block's arguments order to be inverted to > be symmetric to "inject". I believe, given that explanation, that #map_to is a far more appropriate name than #map_into . . . and suddenly the reservations I had about this alias start to fade away. There is a clear semantic distinction between #each_with, where the focus is on the action performed in the block, and #map_to, where the focus is on the object returned from the block. So the question is: is this alias/method meant to be an analogue for #each, or for #map ? -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd --047d7b10d185158dcc04ce5ed7a1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 13 November 2012 2= 1:25, rosenfeld (Rodrigo Rosenfeld Rosas) <rr.rosas@gmail.com> wrote:

Issue #7340 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


The reason I dislike each_with_object and each_with is the "each"= on them. "each"'s return value isn't meaningful to me. T= hat's why I would prefer "map_to", "map_into" or ju= st "into".

"into" here doesn't mean putting values "into" the = array or hash. It means: "turn/map object into a hash/array/whatever&q= uot;. It is not about putting something into the passed object, but about c= onverting the original object (say numbers) into the object being passed as= the initial value like a hash or an array.

It is ok to chain operations as a pattern (like the one used by jQuery) so = that an_array.each{...}.sort would justify "each" returning the o= riginal "an_array", but only to be able to chain operations and n= ot because "each" implies returning anything meaningful.

In that sense, each_with_object is currently supposed to return some meanin= gful value. That is why I'd prefer to call it "map_to", "= ;map_into" or just "into".

numbers.map_into({}){...} should read "map numbers into a hash where .= ..". It would be even shorter if we just abbreviated "map_into&qu= ot; as just "into".

Also, if there is any chance that this wouldn't be an alias to each_wit= h_object, I'd prefer the block's arguments order to be inverted to = be symmetric to "inject".

I belie= ve, given that explanation, that #map_to is a far more appropriate name tha= n #map_into . . . and suddenly the reservations I had about this alias star= t to fade away.

There is a clear semantic distinction between #each_wit= h, where the focus is on the action performed in the block, and #map_to, wh= ere the focus is on the object returned from the block. =A0So the question = is: is this alias/method meant to be an analogue for #each, or for #map ?


--
=A0 Matthe= w Kerwin, B.Sc (CompSci) (Hons)
=A0 http://matthew.kerwin.net.au/
=A0 ABN: 59-01= 3-727-651

=A0 "You'll never find a programming language that frees
= =A0 you from the burden of clarifying your ideas." - xkcd
--047d7b10d185158dcc04ce5ed7a1--