ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:72353] [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects
@ 2015-12-18  4:27 Joseph Jones
  2015-12-18  4:31 ` [ruby-core:72354] " Shugo Maeda
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Jones @ 2015-12-18  4:27 UTC (permalink / raw)
  To: Ruby developers; +Cc: ruby-core

[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]

Joseph Jones liked your message with Boxer. On December 9, 2015 at 09:15:54 MST, sawadatsuyoshi@gmail.com wrote:Issue #11797 has been reported by Tsuyoshi Sawada.----------------------------------------Feature #11797: `Enumerator#with_object` with multiple objectshttps://bugs.ruby-lang.org/issues/11797* Author: Tsuyoshi Sawada* Status: Open* Priority: Normal* Assignee: ----------------------------------------Sometimes, when working with `Enumerator#with_object`, 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://stackoverflow.com/questions/3418123). Suppose I have an enumerator created from an array: e = ["a", "b", "c", "c", "a", "c"].to_enumand want to get an array of its repeated elements in the order they are repeated (i.e., appears for the second time): # => ["c", "a"]I can do it using `Enumerator#with_object` like this: e.to_enum.with_object([{}, []]){|c, (h, a)| h[c] ? a.push(c) : h.store(c, true)}.last.uniqHere, I am getting the array referred to as `a` in the block, but besides that, I am using a temporal hash `h`. I thought it would be nice if `Enumerator#with_object` accepts one or more objects, pass them individually as block arguments, and returns only the last argument so that I can do this: e.to_enum.with_object({}, []){|c, h, a| h[c] ? a.push(c) : h.store(c, true)}.uniq-- https://bugs.ruby-lang.org/     

[-- Attachment #2: Type: text/html, Size: 1884 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:72354] Re: [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects
  2015-12-18  4:27 [ruby-core:72353] [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects Joseph Jones
@ 2015-12-18  4:31 ` Shugo Maeda
  0 siblings, 0 replies; 2+ messages in thread
From: Shugo Maeda @ 2015-12-18  4:31 UTC (permalink / raw)
  To: Ruby developers, ruby-talk

Hello,

I've removed his address from ruby-core and ruby-talk.

2015-12-18 13:27 GMT+09:00 Joseph Jones <joeyi5216@gmail.com>:
> Joseph Jones liked your message with Boxer.
>
>
> On December 9, 2015 at 09:15:54 MST, sawadatsuyoshi@gmail.com wrote:
>
> Issue #11797 has been reported by Tsuyoshi Sawada.
>
> ----------------------------------------
> Feature #11797: `Enumerator#with_object` with multiple objects
> https://bugs.ruby-lang.org/issues/11797
>
> * Author: Tsuyoshi Sawada
> * Status: Open
> * Priority: Normal
> * Assignee:
> ----------------------------------------
> Sometimes, when working with `Enumerator#with_object`, 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://stackoverflow.com/questions/3418123). Suppose I have an enumerator
> created from an array:
>
> e = ["a", "b", "c", "c", "a", "c"].to_enum
>
> and want to get an array of its repeated elements in the order they are
> repeated (i.e., appears for the second time):
>
> # => ["c", "a"]
>
> I can do it using `Enumerator#with_object` like this:
>
> e.to_enum.with_object([{}, []]){|c, (h, a)| h[c] ? a.push(c) : h.store(c,
> true)}.last.uniq
>
> Here, I am getting the array referred to as `a` in the block, but besides
> that, I am using a temporal hash `h`. I thought it would be nice if
> `Enumerator#with_object` accepts one or more objects, pass them individually
> as block arguments, and returns only the last argument so that I can do
> this:
>
> e.to_enum.with_object({}, []){|c, h, a| h[c] ? a.push(c) : h.store(c,
> true)}.uniq
>
>
>
>
> --
> https://bugs.ruby-lang.org/



-- 
Shugo Maeda

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-18  3:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18  4:27 [ruby-core:72353] [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects Joseph Jones
2015-12-18  4:31 ` [ruby-core:72354] " Shugo Maeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).