Mismatch between the order of the type variable and the order of the SAM method formal parameters

Yuval Shavit yshavit at akiban.com
Thu Sep 15 16:09:53 PDT 2011


Why should the lambda usually come last? I admit I'm fairly new to
functional programming, but it seems that functions/lambdas often come first
in methods, which can be useful when currying. I realize that currying isn't
part of this project, but it's conceivable that Java would have it in the
future.

On Thu, Sep 15, 2011 at 12:00 PM, Rémi Forax <forax at univ-mlv.fr> wrote:

> On 09/15/2011 05:56 PM, Brian Goetz wrote:
> > In general, it is best if methods that have a single lambda parameter
> have the lambda parameter last.
>
> I agree for Iterable.reduce, but here it's Reducer.reduce().
>
> Rémi
>
> >
> >
> > On Sep 15, 2011, at 12:30 AM, Rémi Forax wrote:
> >
> >> Hi all,
> >>
> >> Here is the declaration of a Reducer:
> >>
> >>    interface Reducer<T, U>  {
> >>        U reduce(U base, T t);
> >>    }
> >>
> >> and how to use it:
> >>
> >>    Reducer<String, Integer>  reducer = (Integer i, String s) ->  i +
> >> s.length();
> >>
> >> As you see the order of the type argument<String, Integer>  is not
> >> the same as the order of the type of the formal parameter of the lambda
> >> (Integer i, String s).
> >> I think it will be simpler if the signature of reduce() was changed to
> >> swap the two
> >> formal parameters.
> >>
> >> Rémi
> >>
> >>
>
>
>


More information about the lambda-dev mailing list