ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Shugo Maeda <shugo@ruby-lang.org>
To: Ruby developers <ruby-core@ruby-lang.org>, ruby-talk@ruby-lang.org
Subject: [ruby-core:72354] Re: [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects
Date: Fri, 18 Dec 2015 13:31:09 +0900	[thread overview]
Message-ID: <CAOVYHQTd+8N1S6iZ3pE29+vL8Lx2CzcUHkT3SDFcsqe+fQ3zMA@mail.gmail.com> (raw)
In-Reply-To: <74A79E45-A2C2-41B7-81E1-8A73F42EF639@gmail.com>

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

      reply	other threads:[~2015-12-18  3:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOVYHQTd+8N1S6iZ3pE29+vL8Lx2CzcUHkT3SDFcsqe+fQ3zMA@mail.gmail.com \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-talk@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).