From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id C41B919E005C for ; Fri, 18 Dec 2015 12:59:30 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id BBE8EB5D8C3 for ; Fri, 18 Dec 2015 13:31:37 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id CB5CA18CC7E4 for ; Fri, 18 Dec 2015 13:31:37 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 95EE11207BC; Fri, 18 Dec 2015 13:31:21 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from mail-oi0-f46.google.com (mail-oi0-f46.google.com [209.85.218.46]) by neon.ruby-lang.org (Postfix) with ESMTPS id 351911206AD; Fri, 18 Dec 2015 13:31:12 +0900 (JST) Received: by mail-oi0-f46.google.com with SMTP id o62so49273751oif.3; Thu, 17 Dec 2015 20:31:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=xGhpqkBsXomwwknOX+UU9GcRE/EfcuZuY74LcFiupGg=; b=bCRx8YInIOYxkPztQcww6AebvwBo6YYQdAhk+UxSTHALCOZ05/nouRjinGkYLFB48x lNGn9aXA+9GlQCNQEdVsc5D4lnQuZ4q30HCPuOS2EJdX4vwa1GPhv2F7PvX1NPQda/xH AvwRrLRojQRjdZ6N9jqe4Bdp+uNJ0JQDqT8cDZ7jRpvjXkyxeo3dyAir7NFYve2P6AaH wHa75oiFrXMLgNvwZ8mE0QkAdOYSvA1KxL6E1dnudIHfdRWT98jM9YG1pDpd1SLZTZSx 9sOtThJMAwm/weVvqVyUdiGmtfE+PzQHNx2zjGHtCs0GRJlLr7TVh2uGScO/eVz6p3WJ fB2Q== MIME-Version: 1.0 X-Received: by 10.202.170.80 with SMTP id t77mr614340oie.78.1450413069702; Thu, 17 Dec 2015 20:31:09 -0800 (PST) Received: by 10.60.96.103 with HTTP; Thu, 17 Dec 2015 20:31:09 -0800 (PST) In-Reply-To: <74A79E45-A2C2-41B7-81E1-8A73F42EF639@gmail.com> References: <74A79E45-A2C2-41B7-81E1-8A73F42EF639@gmail.com> Date: Fri, 18 Dec 2015 13:31:09 +0900 X-Google-Sender-Auth: IpjYYanZJoP6gXUM90491SXgCng Message-ID: From: Shugo Maeda To: Ruby developers , ruby-talk@ruby-lang.org Content-Type: text/plain; charset=UTF-8 X-ML-Name: ruby-core X-Mail-Count: 72354 Subject: [ruby-core:72354] Re: [Ruby trunk - Feature #11797] [Open] `Enumerator#with_object` with multiple objects X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Hello, I've removed his address from ruby-core and ruby-talk. 2015-12-18 13:27 GMT+09:00 Joseph Jones : > 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