Perl 6 Cool Perl 6 #25

The .classify method

    %addrbook.classify({ .value.substr(0,1).uc })

In this case, .classify is being applied to %addrbook, which acts like a list of "email => name" Pairs.

The { .value.substr(0,1).uc } block is applied to each Pair, returning the uppercase value of the first letter of the name.

This results in a "hash" with the keys being the capitalized first letter of each name, and values are all of the names beginning with that letter.

Copyright © 2010
http://www.pmichaud.com/2010/pres/