Re: Proposal: Replace foreach loop with Iterable.forEach in String.join(CharSequence, Iterable)

2021-08-17 Thread Donald Raab
forEach with a method reference, which IIRC might be slightly better than having a lambda. The underlying collection (let’s say ArrayList) will be called which will also not create an iterator but iterate directly over the ArrayList internal array. Thanks, Don > Thanks! > > /Claes &g

Proposal: Replace foreach loop with Iterable.forEach in String.join(CharSequence, Iterable)

2021-08-16 Thread Donald Raab
The following code: for (CharSequence cs: elements) { joiner.add(cs); } Can be replaced with: elements.forEach(joiner::add); This would have the minor benefit of making it safe to use String.join with synchronized collections without requiring a client side lock. There are likely other

Re: New convenience methods on Stream

2021-06-13 Thread Donald Raab
> collection is non-empty, as you can append into single collection from > existing sources. Essentially, into(c) == forEach(c::add), but it's > also possible to add optimizations for specific collections (like `if > (isSizedStream() && c instanceof ArrayList al) { > al.ensure

Re: Collection::getAny discussion

2021-04-30 Thread Donald Raab
(so much so, in fact, that people are often frustrated by our seeming > conservatism.) > > > > > > > > On 4/30/2021 4:02 PM, Donald Raab wrote: >> There is a default method getAny defined on the RichIterable interface in >> Eclipse Col

Re: Collection::getAny discussion

2021-04-30 Thread Donald Raab
There is a default method getAny defined on the RichIterable interface in Eclipse Collections. Adding a getAny with the same signature to Collection is bound to cause a break similar to CharSequence.isEmpty did with JDK 15 but possibly more extensive since RichIterable is the parent interface

Re: New convenience methods on Stream

2021-04-28 Thread Donald Raab
MutableBiMap biMap = stream.to(array -> ArrayAdapter.adapt(array) .toBiMap(String::toLowerCase, String::toUpperCase)); Thanks, Don > On Apr 27, 2021, at 1:35 AM, Donald Raab wrote: > > I realized after sending that option 2 can be made more abstract: > &

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

Re: ReversibleCollection proposal

2021-04-17 Thread Donald Raab
> I'm also concerned about conflicts over the other method names; something > like addFirst() is a pretty obvious method to add to a custom List > implementation. I haven't seen any, but that doesn't mean there aren't any. > > s'marks The getFirst() and getLast() methods will have

Re: ReversibleCollection proposal

2021-04-17 Thread Donald Raab
> On Apr 17, 2021, at 2:24 PM, Stuart Marks wrote: > > > > On 4/16/21 3:06 PM, Donald Raab wrote: >> We should be cautious when adding new APIs to existing interfaces. There may >> be libraries which extend JDK types and already have reversed(), >>

Re: ReversibleCollection proposal

2021-04-16 Thread Donald Raab
Hi Stuart, We should be cautious when adding new APIs to existing interfaces. There may be libraries which extend JDK types and already have reversed(), toReversed() or asReversed() APIs and corresponding interfaces. There are OrderedIterable and ReversibleIterable interfaces and asReversed()

RFR: 8180352: Add Stream.toList() method

2021-02-04 Thread Donald Raab
I have been reading previous threads, the original bug request, and exploring the javadoc and implementation of toList() on Stream in JDK 16. I don’t want to waste time rehashing previous discussions, but I want to understand and prioritize the motivation of this change, and propose what I