Luke Palmer wrote:
> Aaron Crane writes:
> >   @unsorted
> >     ==> sort &infix:<=>, desc => 1, key => { $_.foo('bar').compute }
> >     ==> @sorted;
> 
> I don't like the C<desc> flag.  But I can't, at the moment, think of any
> way around it short of:
> 
>     @unsorted
>         ==> sort { $^b <=> $^a }, key => { .foo('bar').compute }
>         ==> @sorted
> 
> Which people have made pretty clear that they don't like.

One option might be an 'rsort' function, but I think that's somewhat lacking
in the taste department.

Another might be as simple as

  @unsorted ==> sort ==> reverse ==> @sorted;

But I can see an argument that C<< ==> reverse >> is quite a large code
burden for something so conceptually simple.

I have one other idea, but I can't decide if I like it:

  @unsorted ==> sort &rinfix:cmp ==> @sorted;

That is, rinfix: (or some other name) is like infix:, but gives you a
function that reverses its arguments before actually running the operator.
Perhaps it could even be implemented as a macro.

-- 
Aaron Crane * GBdirect Ltd.
http://training.gbdirect.co.uk/courses/perl/

Reply via email to