Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-23 Thread ІП-24 Олександр Ротань
itect, Java Platform Group > Oracle > > ---------- > *From:* core-libs-dev on behalf of Remi > Forax > *Sent:* Friday, 19 April 2024 19:47 > *To:* ІП-24 Олександр Ротань > *Cc:* core-libs-dev > *Subject:* Re: Addition of Predicate-based findInde

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-23 Thread Viktor Klang
Viktor Klang Software Architect, Java Platform Group Oracle From: core-libs-dev on behalf of Remi Forax Sent: Friday, 19 April 2024 19:47 To: ІП-24 Олександр Ротань Cc: core-libs-dev Subject: Re: Addition of Predicate-based findIndex and findLastIndex m

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-20 Thread ІП-24 Олександр Ротань
Regarding what Holo said, I think enumerated() would be a more suitable name. I have few ideas about implementation of such things, like separate EnumeratedStream interface, which extends stream and provides methods like forEach(BiConsumer), etc. This would eliminate unnecessary object instantiati

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-20 Thread Holo The Sage Wolf
Hello, I want to challenge the idea that every stream may be indexed for 3 reasons: Any sensible type to use for an index (int/long) will be bounded, but streams need not, e.g. new Random().ints().withIndex().forEach(v -> ...); May result (after a very long time) non sensical values. Using bi

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-20 Thread -
Hi Rotan', Interface methods are both exposed to callers and to implementations. Is there any scenario where the implementation can be more efficient than the stream/gatherer scanning approach? indexOf or lastIndexOf may be faster if a list has some tricks like a hashmap to quickly look up the ind

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread ІП-24 Олександр Ротань
Turned out this whole time I was only replying to David. I have to thank him for his patience explaining me how this whole mailing thing work. To summarize what has been missed out, besides what have you seen in quotes. I have pointed out that, while flexibility and simplicity is important, the ma

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
> That was what i referred to as "Map-solvable" problems, > but if this way of doing it is a thing, then I agree with > the point. Doing it the Map way would not only be slower, but it would force you to include more concepts than you need. Your identifier is your index. Lists/arrays have index. B

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
> I think that, while finding the index of a matching > element is not a very common task, especially among > commercial developers, when discussing indexed streams, > this would be the most common use case. To be honest, I > don't even see any other use cases right now, besides > maybe some proces

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
on to use .withIndex(). list .stream() .withIndex() .filter(WithIndex.filter(predicate)) .mapToIndex() .findFirst() .orElse(-1) On Fri, Apr 19, 2024 at 5:47 PM wrote: > > > -- > > *From: *"David Alayachew" > *To: *"Rem

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread forax
> From: "David Alayachew" > To: "Remi Forax" > Cc: "ІП-24 Олександр Ротань" , "core-libs-dev" > > Sent: Friday, April 19, 2024 11:02:12 PM > Subject: Re: Addition of Predicate-based findIndex and findLastIndex methods > to >

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
It is not the goal of Java to be verbose, but it is also not the goal of Java to be concise either. It is the goal of Java to be clear, correct, and readable, in order to maximize maintainability, correctness, and flexibility. When you focus on accomplishing that goal first, you will find that conc

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread ІП-24 Олександр Ротань
Thanks for the advice. Indeed, it was a mistake to implement this before discussing it in mail. This is my first open-source experience, so i guess this will be a valuable experience for my future contributions сб, 20 апр. 2024 г. в 00:12, David Alayachew : > Hello > > Thanks for sending this ema

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
Hello Thanks for sending this email. Your idea makes a lot of sense, but I feel that it only serves a very specific use case. That does not make it bad, but it does make it narrow. I already suggested my idea in my email to Rémi, where the index is just another field in the data type being stream

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread David Alayachew
No Rémi, I don't think your idea is the right approach. You are working on the wrong level of abstraction. Many users ask requests like this all the time, and what you are suggesting would be even more error-prone than the equivalent for loop or the IntStream suggestion that the user above request

Re: Addition of Predicate-based findIndex and findLastIndex methods to java.util.List

2024-04-19 Thread Remi Forax
Hello, for me, it seems what you want is Collector on Stream which is able to short-circuit, so you can write list.stream().collect(Collectors.findFirst(s -> s.contains("o"))) and in reverse list.reversed().stream().collect(Collectors.findFirst(s -> s.contains("o"))) Using a Stream here is