File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -891,8 +891,23 @@ Defined as:
891
891
multi sub classify($test, +items, :$into!, *%named )
892
892
multi sub classify($test, +items, *%named )
893
893
894
- The two first forms will fail.
894
+ The two first forms will fail. The rest include a C < $test > , which is a function
895
+ that will return a scalar for every input; these will be used as keys of a hash
896
+ whose values will be arrays with the elements that output that key for the test
897
+ function.
895
898
899
+ = for code
900
+ my @years = (2003..2008).map( { Date.new( $_~"-01-01" ) } );
901
+ @years.classify( *.is-leap-year , into => my %leap-years );
902
+ say %leap-years;
903
+ # OUTPUT: «{False => [2003-01-01 2005-01-01 2006-01-01 2007-01-01],
904
+ # True => [2004-01-01 2008-01-01]}»
905
+
906
+
907
+ Similarly to L < C < .categorize > |/type/Any#method_categorize> , elements can be
908
+ normalized by the C < Callable > passed with the C < :as > argument, and it can use
909
+ the C < :into > named argument to pass a C < Hash > the results will be classified
910
+ into; in the example above, it's defined on the fly.
896
911
897
912
= head2 method produce
898
913
You can’t perform that action at this time.
0 commit comments