Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: sort +*, @array

by hdb (Monsignor)
on Dec 09, 2013 at 10:09 UTC ( [id://1066266]=note: print w/replies, xml ) Need Help??


in reply to sort +*, @array

And what does say sort +*, @array; actually do?

Replies are listed 'Best First'.
Re^2: sort +*, @array
by raiph (Deacon) on Dec 09, 2013 at 12:32 UTC

      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?

        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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1066266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-18 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found