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".
----------------------------------------
Feature #7340: 'each_with' or 'into' alias for 'each_with_object'
https://bugs.ruby-lang.org/issues/7340#change-32853

Author: nathan.f77 (Nathan Broadbent)
Status: Open
Priority: Low
Assignee: 
Category: lib
Target version: next minor


Following on from the discussions at #7297 and #7241, it is apparent that a shorter alias for 'each_with_object' would be much appreciated.


-- 
http://bugs.ruby-lang.org/