https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-11-13T11:06:51ZRuby Issue Tracking SystemRuby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=328322012-11-13T11:06:51Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I dislike #into because it may or may not put something into the argument.<br>
I am OK with #each_with.</p>
<p>Matz.</p> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=328352012-11-13T11:24:29Zmerborne (kyo endo)
<ul></ul><p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>I dislike #into because it may or may not put something into the argument.<br>
I am OK with #each_with.</p>
<p>Matz.</p>
</blockquote>
<p>I would appreciate if you could look at <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Enumerable#with (Open)" href="https://redmine.ruby-lang.org/issues/6687">#6687</a>. but #each_with is OK for me :-)</p> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=328532012-11-13T20:25:56Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>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".</p>
<p>"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.</p>
<p>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.</p>
<p>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".</p>
<p>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".</p>
<p>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".</p> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=328562012-11-13T20:53:19Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>On 13 November 2012 21:25, rosenfeld (Rodrigo Rosenfeld Rosas) <<br>
<a href="mailto:rr.rosas@gmail.com" class="email">rr.rosas@gmail.com</a>> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: 'each_with' or 'into' alias for 'each_with_object' (Open)" href="https://redmine.ruby-lang.org/issues/7340">#7340</a> has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).</p>
<p>The reason I dislike each_with_object and each_with is the "each" on them.<br>
"each"'s return value isn't meaningful to me. That's why I would prefer<br>
"map_to", "map_into" or just "into".</p>
<p>"into" here doesn't mean putting values "into" the array or hash. It<br>
means: "turn/map object into a hash/array/whatever". It is not about<br>
putting something into the passed object, but about converting the original<br>
object (say numbers) into the object being passed as the initial value like<br>
a hash or an array.</p>
<p>It is ok to chain operations as a pattern (like the one used by jQuery) so<br>
that an_array.each{...}.sort would justify "each" returning the original<br>
"an_array", but only to be able to chain operations and not because "each"<br>
implies returning anything meaningful.</p>
<p>In that sense, each_with_object is currently supposed to return some<br>
meaningful value. That is why I'd prefer to call it "map_to", "map_into" or<br>
just "into".</p>
<p>numbers.map_into({}){...} should read "map numbers into a hash where ...".<br>
It would be even shorter if we just abbreviated "map_into" as just "into".</p>
<p>Also, if there is any chance that this wouldn't be an alias to<br>
each_with_object, I'd prefer the block's arguments order to be inverted to<br>
be symmetric to "inject".</p>
</blockquote>
<p>I believe, given that explanation, that #map_to is a far more appropriate<br>
name than #map_into . . . and suddenly the reservations I had about this<br>
alias start to fade away.</p>
<p>There is a clear semantic distinction between #each_with, where the focus<br>
is on the action performed in the block, and #map_to, where the focus is on<br>
the object returned from the block. So the question is: is this<br>
alias/method meant to be an analogue for #each, or for #map ?</p>
<p>--<br>
Matthew Kerwin, B.Sc (CompSci) (Hons)<br>
<a href="http://matthew.kerwin.net.au/" class="external">http://matthew.kerwin.net.au/</a><br>
ABN: 59-013-727-651</p>
<p>"You'll never find a programming language that frees<br>
you from the burden of clarifying your ideas." - xkcd</p> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=466682014-05-10T15:21:25Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/7384">Feature #7384</a>: Rename #each_with_object to #each_with</i> added</li></ul> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=466702014-05-10T15:22:30Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/7297">Feature #7297</a>: map_to alias for each_with_object</i> added</li></ul> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=466722014-05-10T15:23:00Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/6687">Feature #6687</a>: Enumerable#with</i> added</li></ul> Ruby master - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://redmine.ruby-lang.org/issues/7340?journal_id=688402017-12-25T18:15:08Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.6</i></del>)</li></ul>