in reply to Re^2: sort +*, @array
in thread sort +*, @array

Thanks for your reply.

So it is the Perl 6 equivalent to say sort {$a <=> $b} @array;?

But how is that statement related to the Schwartzian transformation?

Replies are listed 'Best First'.
Re^4: sort +*, @array
by raiph (Deacon) on Dec 09, 2013 at 13:53 UTC
    The +* is a "key extractor" closure. This closure corresponds to the before map of the ST. Of course, in the specific case of +*, it's trivial to instead just specify a "comparator" closure using <=>, but what if one instead writes:

    say sort +*.value, 1=>4, 11=>5, 2=>99, 22=>22, 3=>339 # prints 1=>4 11=>5 22=>22 2=>99 3=>339 say sort ~*.value, 1=>4, 11=>5, 2=>99, 22=>22, 3=>339 # prints 22=>22 3=>339 1=>4 11=>5 2=>99

    (And of course the results of the closure call on a given item is memoized.)

      Thanks for the explanation. So the link to the Schwartzian really is the fact that the items are automatically memoized.