Hi ,

I suggest that the withIndex method in DefaultGroovyMethods is overloaded with 
an option to support streams as well

Given

names = ['per', 'karin', 'tage', 'arne', 'sixten', 'ulrik']

I can find the 4:th element with
println names[3]

or if I only have an iterator with
println names.iterator().withIndex().find { it, idx -> 3 == idx }[0]

For a stream I can do it by using a java.util.concurrent.atomic.AtomicInteger:
AtomicInteger index = new AtomicInteger()
println names.stream().find(n -> 3 == index.getAndIncrement())

I have seen that libraries more and more often will expose a stream api rather 
than a Collection or an Iterator so it would be very nice if I could just do
println names.stream().withIndex().find { it, idx -> 3 == idx}[0]

or alternatively add a findWithIndex so that this would be possible:
println names.stream().findWithIndex { it, idx -> 3 == idx}

What do you think?

Regards,
Per

Reply via email to