groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject Re: CharSequence.count(Closure)
Date Fri, 22 May 2015 14:41:34 GMT

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.

View raw message