Bikeshed opportunity: compose vs composeWith (original) (raw)
Brian Goetz brian.goetz at oracle.com
Tue Nov 27 08:04:19 PST 2012
- Previous message: Bikeshed opportunity: compose vs composeWith
- Next message: Bikeshed opportunity: compose vs composeWith
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I like "thenComparing". Done?
Separately, would "reverseOrder" be better / more consistent for the extension method on Comparator than the current "reverse"? (There's already a Collections.reverseOrder static method.)
On 11/27/2012 10:35 AM, Kevin Bourrillion wrote:
I think it's very helpful for these two names to have parallel structure:
comparingBy / thenBy or comparing / thenComparing
On Mon, Nov 26, 2012 at 2:48 PM, Raab, Donald <Donald.Raab at gs.com_ _<mailto:Donald.Raab at gs.com>> wrote: What about this? people.sort(comparing(Person::getLast).thenBy(Person::getFirst)) > -----Original Message----- > From: Raab, Donald [Tech] > Sent: Monday, November 26, 2012 5:45 PM > To: 'Brian Goetz'; Sam Pullara > Cc: lambda-libs-spec-experts at openjdk.java.net <mailto:lambda-libs-spec-experts at openjdk.java.net> > Subject: RE: Bikeshed opportunity: compose vs composeWith > > Just out of curiosity,I opened up Microsoft Excel and looked how they > word multi-level sorts. > > Sort By -> Column A > Then By -> Column B > Then By -> Column C > Etc. > > So "then" in the wording definitely looks good. Not sure if there is > anything better than thenCompare. > > This would be cool to read, but is a different animal. > > people.sortBy(Person::getLast).thenBy(Person::getFirst) > > We use the word "chain" on our Comparators static utility class in GS > Collections with varargs. But since you are adding this method to > Comparator, not sure if chain or chainWith would be a good name. > > > -----Original Message----- > > From: lambda-libs-spec-experts-bounces at openjdk.java.net <mailto:lambda-libs-spec-experts-bounces at openjdk.java.net> > > [mailto:lambda- mailto:lambda-_ _libs-spec-experts-bounces at openjdk.java.net <mailto:libs-spec-experts-bounces at openjdk.java.net>] On Behalf > > Of Brian Goetz > > Sent: Monday, November 26, 2012 3:07 PM > > To: Sam Pullara > > Cc: lambda-libs-spec-experts at openjdk.java.net <mailto:lambda-libs-spec-experts at openjdk.java.net> > > Subject: Re: Bikeshed opportunity: compose vs composeWith > > > > I like the "then" convention to indicate sequencing. In context: > > > > people.sort(comparing(Person::getLast) > > .thenCompare(comparing(Person::getFirst))) > > > > > > > > On 11/26/2012 3:04 PM, Sam Pullara wrote: > > > How about something that sounds more comparator specific: > > > > > > comparator1.thenCompare(comparator2) > > > > > > Sam > > > > > > On Nov 26, 2012, at 11:57 AM, Kevin Bourrillion <kevinb at google.com <mailto:kevinb at google.com> > > > <mailto:kevinb at google.com <mailto:kevinb at google.com>>> wrote: > > > > > >> So... comparator1.compound(comparator2)? > > >> > > >> > > >> On Mon, Nov 26, 2012 at 11:10 AM, Brian Goetz > > <brian.goetz at oracle.com <mailto:brian.goetz at oracle.com> > > >> <mailto:brian.goetz at oracle.com_ _<mailto:brian.goetz at oracle.com>>> wrote: > > >> > > >> However, this is the first time I'm noticing that you're > > using > > >> the name > > >> compose() not only for function composition, but also for > > >> forming a > > >> compound comparator. Has it been suggested that we not > > reuse the > > >> compose() name to mean this other thing? Note that there > > does > > >> exist a > > >> compose operation for Comparators, but it's (Function, > > >> Comparator) -> > > >> Comparator (Guava puts it in the other order and calls it > > >> "onResultOf", > > >> which I'm not recommending). > > >> > > >> > > >> It has not been suggested until now. I am fine calling this > > >> something that does not contain the string "compose". The key > > >> concept is "I have two comparators, and I want to build a > > >> dictionary-order comparator for (O1, O2)." > > >> > > >> I am fine with .compose() for functions. > > >> > > >> I think .compose(other) is too cryptic for comparators. I > think > > >> .composeWith() is better; I can imagine there are other things > > >> that are also better. Now taking suggestions. (Though > > onResultOf > > >> does not seem better.) > > >> > > >> > > >> > > >> > > >> -- > > >> Kevin Bourrillion | Java Librarian | Google, Inc. > > >> |kevinb at google.com <mailto:kevinb at google.com> <mailto:kevinb at google.com <mailto:kevinb at google.com>> > > >> > > > -- Kevin Bourrillion | Java Librarian | Google, Inc. |kevinb at google.com <mailto:kevinb at google.com>
- Previous message: Bikeshed opportunity: compose vs composeWith
- Next message: Bikeshed opportunity: compose vs composeWith
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list