Re: New convenience methods on Stream

2021-06-13 Thread Donald Raab
Thank you for the response Tagir! The intent of all three of these proposals to was to explore better ways of providing improved interop between Streams and 3rd party collection libraries. I agree with you on option 1. This is my least favorite option, but seemed the most obvious shortcut and

Re: New convenience methods on Stream

2021-05-09 Thread dfranken . jdk
>From my own limited experience, I've seen .collect(Supplier) often when an explicitly mutable collection is needed, such as with ArrayList::new or HashSet::new. Even though you could in theory use Stream.toList() for the ArrayList version, I don't think this is advisable as toList isn't guarantee

Re: New convenience methods on Stream

2021-05-04 Thread Stuart Marks
Hi Don, When evaluating new APIs I always find it helpful and educational to look for cases in real code where they might be applied, and what effect the API has at the call site. The search need not be exhaustive, but it's probably sufficient to find a number of representative examples. This

Re: New convenience methods on Stream

2021-04-30 Thread Tagir Valeev
Hello! 1. toCollection looks too specific to be added to JDK. Essentially, it's a shortcut for toCollection constructor and unlike toList, it cannot add many optimizations there. So we basically save several characters and nothing more. And toCollection collector is orders of magnitude less used t

Re: New convenience methods on Stream

2021-04-28 Thread Donald Raab
I looked through a few libraries and found some methods where the option #2 proposal for Steam might be useful. If the JDK had constructors for ArrayList, HashSet and other collection types that take arrays this method would work there as well. > default > R to(Function function) > { >retu

Re: New convenience methods on Stream

2021-04-26 Thread Donald Raab
I realized after sending that option 2 can be made more abstract: default > R to(Function function) { return function.apply((T[]) this.toArray()); } > > 2. Pass the result of toArray directly into a function that can then return a > Collection. This should work with Set.of, List.of and any

New convenience methods on Stream

2021-04-26 Thread Donald Raab
Hi all, I’d like to propose adding one or two of the following methods on Stream to cover more surface area of the Collections ecosystem, without requiring a big increase in the size of the Stream interface. Apologies if this has come up for discussion before. 1. Stream contents into a mutab