Statocles
view release on metacpan or search on metacpan
lib/Statocles/Util.pm view on Meta::CPAN
#pod =sub uniq_by
#pod
#pod my @uniq_links = uniq_by { $_->href } @links;
#pod
#pod Filter a list into its unique items based on the result of the passed-in block.
#pod This lets us get unique links from their C<href> attribute.
#pod
#pod =cut
sub uniq_by(&@) {
my ( $sub, @list ) = @_;
my ( %found, @out );
for my $i ( @list ) {
local $_ = $i;
push @out, $i if !$found{ $sub->() }++;
}
return @out;
}
#pod =sub derp
( run in 0.926 second using v1.01-cache-2.11-cpan-49f99fa48dc )