Bikeshed opportunity: compose vs composeWith

Brian Goetz brian.goetz at oracle.com
Mon Nov 26 10:01:12 PST 2012


We've got two changesets in flight that introduce a compose method:

interface Function<T,R> {
     default<U> Function<T,U> compose(Function<R,U> other) { ... }
}


interface Comparator<T> {
     // create a dictionary-order comparator
     default Comparator<T> compose(Comparator<T> other) { ... }
}


We received some feedback that users found "compose()" at the use-site 
slightly ambiguous.  I'm starting to lean towards "composeWith(fn)", 
despite it being slightly more wordy.  Preferences?

   Comparator byFirst = Comparators.comparing(Person::getFirstName);
   Comparator byLast = Comparators.comparing(Person::getLastName);
   Comparator byFirstLast = byLast.composeWith(byFirst);



More information about the lambda-libs-spec-observers mailing list