Into (original) (raw)
Remi Forax forax at univ-mlv.fr
Wed Dec 26 08:52:24 PST 2012
- Previous message: Into
- Next message: Into
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 12/26/2012 04:40 PM, Doug Lea wrote:
On 12/26/12 10:23, Remi Forax wrote:
that's why we need two different stream ops, toList/toSet should conserve the property of the source i.e. create the 'right' Set or List implementation depending on the source property and into that uses the destination property.
The second problem is what is the interface of a stream which is split to be computed in parallel in order to be gathered without using an intermediary data structure as now. For toList/toSet, because the pipeline implementation control the Set/List implementation, so there is no need of such interface, for into(), the question is is with interface pull it's own weight or not ? Right. My line of thought was: We'll need/want the to-* versions anyway. Given this, do the Reducers/Tabulators pull their weight? People can always define such things themselves layered on top of stream API. While I'm at it, here's a fleshed out version of one possible to-* API. (Note: under this scheme methods sorted() and unique() go away).
No, I think it's better to have only toList() and toSet(), the result of stream.sorted().toSet() will return a NavigableSet/SortedSet. The idea is that the method to* will choose the best implementation using the property of the pipeline.
If you want a specific implementation, then use into().
Maybe, for toSet, we have two methods (toSet and toNavigableSet) but in that case, if the element of the pipeline are not sorted (by using sorted() or because the source collection is a navigable set and ops specified doesn't modify the order) then it should throw an exception.
Given that, here is my wish list,
U[] toArray(Class clazz); // may throw an ArrayStoreException Set toSet() // may throw an IllegalStateException if elements are not unique NavigableSet toSortedSet() // may throw an IllegalStateException if elements are not sorted and unique List toList(); // always returns a random access list, if you want a sequential list use into(new LinkedList<>()). List toSortedList(); // always returns a random access list, may throw an IllegalStateException if elements are not sorted
and all of them are implemented in the Stream interface as default methods checking the pipeline flags and delegating to into().
Object[] toArray(); Set toSet(); List toList(); List toRandomAccessList(); List toSortedList(Comparator<? super T> comparator); List toSortedList(); NavigableSet toSortedSet(); NavigableSet toSortedSet(Comparator<? super T> comparator); Collection toBag(); // unordered, possible dups Map<K,T> toMap(Function<? super T,K> keyFn, BinaryOperator mergeFn); Map<K,<Collection> toMap(Function<? super T,K> keyFn); NavigableMap<K,T> toSortedMap(Function<? super T,K> keyFn, Comparator<? super K> comparator, BinaryOperator mergeFn); NavigableMap<K,Collection> toSortedMap(Function<? super_ _T,K> keyFn, Comparator<? super_ _K> comparator);
Rémi
- Previous message: Into
- Next message: Into
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-experts mailing list