Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: sort +*, @array

by raiph (Hermit)
on Dec 09, 2013 at 13:53 UTC ( #1066289=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^4: sort +*, @array
Select or Download Code
Re^5: sort +*, @array
by hdb (Prior) on Dec 09, 2013 at 14:26 UTC

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (18)
As of 2014-10-30 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls