Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds example for classify refs #1731
  • Loading branch information
JJ committed Feb 19, 2019
1 parent 782a7de commit 048d6e0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doc/Type/Any.pod6
Expand Up @@ -891,8 +891,23 @@ Defined as:
multi sub classify($test, +items, :$into!, *%named )
multi sub classify($test, +items, *%named )
The two first forms will fail.
The two first forms will fail. The rest include a C<$test>, which is a function
that will return a scalar for every input; these will be used as keys of a hash
whose values will be arrays with the elements that output that key for the test
function.
=for code
my @years = (2003..2008).map( { Date.new( $_~"-01-01" ) } );
@years.classify( *.is-leap-year , into => my %leap-years );
say %leap-years;
# OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
# True => [2004-01-01 2008-01-01]}␤»
Similarly to L<C<.categorize>|/type/Any#method_categorize>, elements can be
normalized by the C<Callable> passed with the C<:as> argument, and it can use
the C<:into> named argument to pass a C<Hash> the results will be classified
into; in the example above, it's defined on the fly.
=head2 method produce
Expand Down

0 comments on commit 048d6e0

Please sign in to comment.