Perl 6 Cool Perl 6 #24

The .classify method

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

Example:

my %hash = @list.classify( { $_ % 2 ?? 'odd' !! 'even' } );

say %hash<even>.perl;  # list of even elements in @list
say %hash<odd>.perl;   # list of odd elements in @list
Copyright © 2010
http://www.pmichaud.com/2010/pres/