RE: withIndex for streams

2025-03-28 Thread Merlin Beedell
ers@groovy.apache.org Subject: Re: withIndex for streams For interest, the code using Gatherers4J looks like: assert names.stream() .gather(Gatherers4j.filterIndexed {index, element -> index == 3 }) // JDK24 .findFirst().get() == 'arne' You can also use something

Re: withIndex for streams

2025-03-23 Thread Paul King
For interest, the code using Gatherers4J looks like: assert names.stream() .gather(Gatherers4j.filterIndexed {index, element -> index == 3 }) // JDK24 .findFirst().get() == 'arne' You can also use something like this using vanilla streams: assert names.stream().skip(3).li

Re: withIndex for streams

2025-03-22 Thread Paul King
It might be worth exploring this. I'll note that gatherers (JDK 24) provide a hook for adding such functionality in Java. Gatherers4j has withIndex (though we'd likely implement it differently): https://tginsberg.github.io/gatherers4j/gatherers/sequence-operations/withindex/ As well as a bunch of

withIndex for streams

2025-03-20 Thread Per Nyfelt
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.iterato