https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?15064139052012-11-13T11:06:51ZRuby Issue Tracking SystemRuby trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.ruby-lang.org/issues/7340?journal_id=328322012-11-13T11:06:51Zmatz (Yukihiro Matsumoto)matz@ruby-lang.org
<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 trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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://bugs.ruby-lang.org/issues/6687">#6687</a>. but #each_with is OK for me :-)</p>
Ruby trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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 &quot;each&quot; on them. &quot;each&quot;&#39;s return value isn&#39;t meaningful to me. That&#39;s why I would prefer &quot;map_to&quot;, &quot;map_into&quot; or just &quot;into&quot;.</p>
<p>&quot;into&quot; here doesn&#39;t mean putting values &quot;into&quot; the array or hash. It means: &quot;turn/map object into a hash/array/whatever&quot;. 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 &quot;each&quot; returning the original &quot;an_array&quot;, but only to be able to chain operations and not because &quot;each&quot; implies returning anything meaningful.</p>
<p>In that sense, each_with_object is currently supposed to return some meaningful value. That is why I&#39;d prefer to call it &quot;map_to&quot;, &quot;map_into&quot; or just &quot;into&quot;.</p>
<p>numbers.map_into({}){...} should read &quot;map numbers into a hash where ...&quot;. It would be even shorter if we just abbreviated &quot;map_into&quot; as just &quot;into&quot;.</p>
<p>Also, if there is any chance that this wouldn&#39;t be an alias to each_with_object, I&#39;d prefer the block&#39;s arguments order to be inverted to be symmetric to &quot;inject&quot;.</p>
Ruby trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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) &lt;<br>
<a href="mailto:rr.rosas@gmail.com">rr.rosas@gmail.com</a>&gt; wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: &#39;each_with&#39; or &#39;into&#39; alias for &#39;each_with_object&#39; (Open)" href="https://bugs.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 &quot;each&quot; on them.<br>
&quot;each&quot;&#39;s return value isn&#39;t meaningful to me. That&#39;s why I would prefer<br>
&quot;map_to&quot;, &quot;map_into&quot; or just &quot;into&quot;.</p>
<p>&quot;into&quot; here doesn&#39;t mean putting values &quot;into&quot; the array or hash. It<br>
means: &quot;turn/map object into a hash/array/whatever&quot;. 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 &quot;each&quot; returning the original<br>
&quot;an_array&quot;, but only to be able to chain operations and not because &quot;each&quot;<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&#39;d prefer to call it &quot;map_to&quot;, &quot;map_into&quot; or<br>
just &quot;into&quot;.</p>
<p>numbers.map_into({}){...} should read &quot;map numbers into a hash where ...&quot;.<br>
It would be even shorter if we just abbreviated &quot;map_into&quot; as just &quot;into&quot;.</p>
<p>Also, if there is any chance that this wouldn&#39;t be an alias to<br>
each_with_object, I&#39;d prefer the block&#39;s arguments order to be inverted to<br>
be symmetric to &quot;inject&quot;.</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/">http://matthew.kerwin.net.au/</a><br>
ABN: 59-013-727-651</p>
<p>&quot;You&#39;ll never find a programming language that frees<br>
you from the burden of clarifying your ideas.&quot; - xkcd</p>
Ruby trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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 trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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 trunk - Feature #7340: 'each_with' or 'into' alias for 'each_with_object'https://bugs.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>