ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Joseph Jones <joeyi5216@gmail.com>
To: Ruby developers <ruby-core@ruby-lang.org>
Cc: <ruby-core@ruby-lang.org>
Subject: [ruby-core:72353] [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects
Date: Thu, 17 Dec 2015 21:27:47 -0700	[thread overview]
Message-ID: <74A79E45-A2C2-41B7-81E1-8A73F42EF639@gmail.com> (raw)

[-- 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 --]

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-18  4:27 Joseph Jones [this message]
2015-12-18  4:31 ` [ruby-core:72354] Re: [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects Shugo Maeda

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=74A79E45-A2C2-41B7-81E1-8A73F42EF639@gmail.com \
    --to=ruby-core@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).