Return-Path: X-Original-To: apmail-groovy-dev-archive@minotaur.apache.org Delivered-To: apmail-groovy-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 457A91734E for ; Fri, 22 May 2015 14:42:03 +0000 (UTC) Received: (qmail 26820 invoked by uid 500); 22 May 2015 14:42:03 -0000 Delivered-To: apmail-groovy-dev-archive@groovy.apache.org Received: (qmail 26781 invoked by uid 500); 22 May 2015 14:42:03 -0000 Mailing-List: contact dev-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.incubator.apache.org Delivered-To: mailing list dev@groovy.incubator.apache.org Received: (qmail 26771 invoked by uid 99); 22 May 2015 14:42:02 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 May 2015 14:42:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 87C0FC0044 for ; Fri, 22 May 2015 14:42:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.981 X-Spam-Level: X-Spam-Status: No, score=0.981 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id TvcoVpYmlSro for ; Fri, 22 May 2015 14:41:53 +0000 (UTC) Received: from nschwmtas05p.mx.bigpond.com (nschwmtas05p.mx.bigpond.com [61.9.189.149]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 271CA206B2 for ; Fri, 22 May 2015 14:41:52 +0000 (UTC) Received: from nschwcmgw08p ([61.9.190.168]) by nschwmtas05p.mx.bigpond.com with ESMTP id <20150522144135.YOIP28484.nschwmtas05p.mx.bigpond.com@nschwcmgw08p> for ; Fri, 22 May 2015 14:41:35 +0000 Received: from [127.0.0.1] ([124.185.246.55]) by nschwcmgw08p with BigPond Outbound id X2ha1q00P1CSq3g012haBE; Fri, 22 May 2015 14:41:35 +0000 X-Authority-Analysis: v=2.0 cv=F6HVh9dN c=1 sm=1 a=1/yBMblUadcsIHiGJfTEWA==:17 a=2VfcibfJTP8A:10 a=IkcTkHD0fZMA:10 a=v5IiRebxAAAA:8 a=_6GpL_ENAAAA:8 a=9iv_ux4bZEjqHK42fk8A:9 a=QEXdDO2ut3YA:10 a=1/yBMblUadcsIHiGJfTEWA==:117 Message-ID: <555F401E.4030305@asert.com.au> Date: Sat, 23 May 2015 00:41:34 +1000 From: Paul King User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: dev@groovy.incubator.apache.org Subject: Re: CharSequence.count(Closure) References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 150522-0, 22/05/2015), Outbound message X-Antivirus-Status: Clean Currently you'd need to do something like: "hello".iterator().count{ "aeiou".contains(it) } I think it makes sense to add a direct DGM method in this instance. And yes, I suspect that CharSequence versions of most of the Iterable DGM methods would be appropriate. Cheers Paul. On 23/05/2015 12:13 AM, Peter Ledbrook wrote: > Hi, > > One of the things I really like about Groovy is how strings can be treated as sequences of characters. Unfortunately this seems to break down in some cases. For example, there is no `count()` method that takes a closure. In my case I'm trying to count vowels, but you might want to count upper case letters or anything else like that. > > Does it make sense to extend all the Iterable methods and properties to CharSequence as well? Or should developers turn a string into a list, perform the processing and then convert it back? Either way, the current setup seems a bit inconsistent. > > Peter > --- This email has been checked for viruses by Avast antivirus software. http://www.avast.com