flatMap signature

Boaz Nahum boaznahum at gmail.com
Tue Apr 2 12:05:19 PDT 2013


Stream:
   (Your suggestion)
<R> R collect(Supplier<*? extends* R> resultFactory,
                  BiConsumer<*? super* R, ? super T> accumulator,
                  BiConsumer<*? super* R, *? super* R> combiner);

--------------------------------------------------------------------------------------------------------
XXXStream:

<U> Stream<U> mapToObj(XXXFunction<*? extends* U> mapper);

<R> R collect(Supplier<*? extends* R> resultFactory,
                  ObjXXXConsumer<*? super* R> accumulator,
                  BiConsumer<*? super* R, *? super* R> combiner);


--------------------------------------------------------------------------------------------------------
Streams:

Because it can be easily proven that Spliterator<? extends T> can be safely
cast to Spliterator<T>,
then you might consider in the following methods replace Spliterator<T>
with Spliterator<? extends T>

public static<T> Stream<T> stream(Supplier<? extends Spliterator<T>>
supplier, int characteristics)
public static<T> Stream<T> parallelStream(Supplier<? extends
Spliterator<T>> supplier, int characteristics)
public static<T> Stream<T> stream(Spliterator<T> spliterator)
public static<T> Stream<T> parallelStream(Spliterator<T> spliterator)

--------------------------------------------------------------------------------------------------------

Also there are some others that I can't find a way to improve, although I
'feel' the need, like:
<R> Stream<R> flatMap(FlatMapper<? super T, R> mapper);


--------------------------------------------------------------------------------------------------------



On Tue, Apr 2, 2013 at 3:44 PM, Boaz Nahum <boaznahum at gmail.com> wrote:

> Stream:
>
> -----------------------------------------------------------------------------------------------------------
> As Brian correct me:
> <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>>
> mapper);
>
> instead of:
> <R> Stream<R> flatMap(Function<T, Stream<? extends R>> mapper);
>
>
> -----------------------------------------------------------------------------------------------------------
> T reduce(T identity, BinaryOperator<T> accumulator);
> and
>  Optional<T> reduce(BinaryOperator<T> accumulator);
>
> Can't be fixed because they used 'BinaryOperator', But if 'BiFunction' is
> used then we have more flexibility
>
> ------------------------------------------------------------------------------------------------------------
> <U> U reduce(U identity,
>                      BiFunction<? super U, ? super T, ? extends U>
> accumulator,
>                      BinaryOperator<U> combiner)
>
> Instead of:
>
>   <U> U reduce(U identity,
>                  BiFunction<U, ? super T, U> accumulator,
>                  BinaryOperator<U> combiner);
>
> Same comment regarding 'BinaryOperator'
>
>
> ------------------------------------------------------------------------------------------------------------
> <R> R collect(Supplier<R> resultFactory,
>                       BiConsumer<? super R, ? super T> accumulator,
>                       BiConsumer<? super R, ? super R> combiner)
>
> Instead of:
>
>     <R> R collect(Supplier<R> resultFactory,
>                   BiConsumer<R, ? super T> accumulator,
>                   BiConsumer<R, R> combiner);
>
>
> I tested all my suggestions with examples and pseudo implementation,
> example:
>
> default <U> U reduce(U identity,
>                      BiFunction<? super U, ? super T, ? extends U>
> accumulator,
>                      BinaryOperator<U> combiner) {
>
>             Collection<T> _this = ....
>
>             U result = identity;
>
>             for (T element : _this)
>                    result = accumulator.apply(result, element);
>
>             return combiner.apply(identity, result);
>
>         }
>
> If you find my comments useful, I will be more than glad to continue on
> other API.
>
>
>
>
> On Mon, Apr 1, 2013 at 1:32 PM, Remi Forax <forax at univ-mlv.fr> wrote:
>
>> On 03/31/2013 05:10 PM, Boaz Nahum wrote:
>> > I have some problems when compiling with flatMap,
>> >
>> > *Maybe* the signature should be:
>> >
>> > <R> Stream<R> flatMap(Function<? super T, Stream<? extends R>> mapper);
>> >
>> > Instead of:
>> >
>> > <R> Stream<R> flatMap(Function<T, Stream<? extends R>> mapper);
>> >
>>
>> yes, probably,
>> I will do a pass on the whole API to fix all wildcards,
>> if you or anybody on this list want to help me,
>> it would be great.
>>
>> cheers,
>> Rémi
>>
>>
>>
>


More information about the lambda-dev mailing list