From: Joseph Jones Date: 2015-12-17T21:27:47-07:00 Subject: [ruby-core:72353] [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects --56738b43_1df029d3_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 9, 2015 at 09:15:= 54 MST, sawadatsuyoshi=40gmail.com wrote:Issue =2311797 has been reported= by Tsuyoshi Sawada.----------------------------------------=46eature =23= 11797: =60Enumerator=23with=5Fobject=60 with multiple objectshttps://bugs= .ruby-lang.org/issues/11797* Author: Tsuyoshi Sawada* Status: Open* Prior= ity: Normal* Assignee: ----------------------------------------Sometimes,= when working with =60Enumerator=23with=5Fobject=60, I want to keep some = additional temporary objects besides the one to return. A use case is as = follows (I got this from this StackOverflow question: http://stackoverflo= w.com/questions/3418123). Suppose I have an enumerator created from an ar= ray: e =3D =5B=22a=22, =22b=22, =22c=22, =22c=22, =22a=22, =22c=22=5D.to=5F= enumand want to get an array of its repeated elements in the order they a= re repeated (i.e., appears for the second time): =23 =3D> =5B=22c=22, =22= a=22=5DI can do it using =60Enumerator=23with=5Fobject=60 like this: e.to= =5Fenum.with=5Fobject(=5B=7B=7D, =5B=5D=5D)=7B=7Cc, (h, a)=7C h=5Bc=5D =3F= a.push(c) : h.store(c, true)=7D.last.uniqHere, I am getting the array re= ferred to as =60a=60 in the block, but besides that, I am using a tempora= l hash =60h=60. I thought it would be nice if =60Enumerator=23with=5Fobje= ct=60 accepts one or more objects, pass them individually as block argume= nts, and returns only the last argument so that I can do this: e.to=5Fenu= m.with=5Fobject(=7B=7D, =5B=5D)=7B=7Cc, h, a=7C h=5Bc=5D =3F a.push(c) : = h.store(c, true)=7D.uniq-- https://bugs.ruby-lang.org/ --56738b43_1df029d3_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 9, 2015 at 09:15:54 MST, sawadatsuyoshi=40gmail.com wrote:
Issue =2311797 has been = reported by Tsuyoshi Sawada.

---------------------------------= -------
=46eature =2311797: =60Enumerator=23with=5Fobject=60 with mu= ltiple objects
https://bugs.ruby-lang.org/issues/11797

* = Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
= * Assignee:
----------------------------------------
Sometimes= , when working with =60Enumerator=23with=5Fobject=60, I want to keep some= additional temporary objects besides the one to return. A use case is as= follows (I got this from this StackOverflow question: http://stackoverfl= ow.com/questions/3418123). Suppose I have an enumerator created from an a= rray:

e =3D =5B=22a=22, =22b=22, =22c=22, =22c=22, =22a=22= , =22c=22=5D.to=5Fenum

and want to get an array of its repeate= d elements in the order they are repeated (i.e., appears for the second t= ime):

=23 =3D> =5B=22c=22, =22a=22=5D

I can do = it using =60Enumerator=23with=5Fobject=60 like this:

e.to=5F= enum.with=5Fobject(=5B=7B=7D, =5B=5D=5D)=7B=7Cc, (h, a)=7C h=5Bc=5D =3F a= .push(c) : h.store(c, true)=7D.last.uniq

Here, I am getting th= e array referred to as =60a=60 in the block, but besides that, I am using= a temporal hash =60h=60. I thought it would be nice if =60Enumerator=23w= ith=5Fobject=60 accepts one or more objects, pass them individually as bl= ock arguments, and returns only the last argument so that I can do this:<= br />
e.to=5Fenum.with=5Fobject(=7B=7D, =5B=5D)=7B=7Cc, h, a=7C = h=5Bc=5D =3F a.push(c) : h.store(c, true)=7D.uniq



=
--
https://bugs.ruby-lang.org/
= --56738b43_1df029d3_16c--