txt: ## classify.md
  classify
  
  Combined from primary sources listed below.
  
  # [In Any](#___top "go to top of document")[§](#(Any)_routine_classify "direct link")
  
  See primary documentation
  [in context](/type/Any#routine_classify)
  for **routine classify**.
  
  ```raku
  multi method classify()
  multi method classify(Whatever)
  multi method classify($test, :$into!, :&as)
  multi method classify($test, :&as)
  multi        classify($test, +items, :$into!, *%named )
  multi        classify($test, +items, *%named )
  ```
  
  The first form will always fail. The second form classifies on the identity of the given object, which usually only makes sense in combination with the `:&as` argument.
  
  The rest include a `$test` argument, 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.
  
  ```raku
  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 [`.categorize`](/type/Any#routine_categorize), elements can be normalized by the [`Callable`](/type/Callable) passed with the `:as` argument, and it can use the `:into` named argument to pass a [`Hash`](/type/Hash) the results will be classified into; in the example above, it's defined on the fly.
  
  From version 6.d, `.classify` will also work with [`Junction`](/type/Junction)s.
  
  Support for using [`Whatever`](/type/Whatever) as the test was added in Rakudo compiler version 2023.02.
  
  # [In List](#___top "go to top of document")[§](#(List)_routine_classify "direct link")
  
  See primary documentation
  [in context](/type/List#routine_classify)
  for **routine classify**.
  
  ```raku
  multi method classify($test, :$into!, :&as)
  multi method classify($test, :&as)
  multi        classify($test, +items, :$into!, *%named )
  multi        classify($test, +items, *%named )
  ```
  
  Transforms a list of values into a hash representing the classification of those values; each hash key represents the classification for one or more of the incoming list values, and the corresponding hash value contains an array of those list values classified into the category of the associated key. `$test` will be an expression that will produce the hash keys according to which the elements are going to be classified.
  
  Example:
  
  ```raku
  say classify { $_ %% 2 ?? 'even' !! 'odd' }, (1, 7, 6, 3, 2);
  # OUTPUT: «{even => [6 2], odd => [1 7 3]}␤»
  say ('hello', 1, 22/7, 42, 'world').classify: { .Str.chars };
  # OUTPUT: «{1 => [1], 2 => [42], 5 => [hello world], 8 => [3.142857]}␤»
  ```
  
  It can also take `:as` as a named parameter, transforming the value before classifying it:
  
  ```raku
  say <Innie Minnie Moe>.classify( { $_.chars }, :as{ lc $_ });
  # OUTPUT: «{3 => [moe], 5 => [innie], 6 => [minnie]}␤»
  ```
  
  This code is classifying by number of characters, which is the expression that has been passed as `$test` parameter, but the `:as` block lowercases it before doing the transformation. The named parameter `:into` can also be used to classify *into* a newly defined variable:
  
  ```raku
  <Innie Minnie Moe>.classify( { $_.chars }, :as{ lc $_ }, :into( my %words{Int} ) );
  say %words; # OUTPUT: «{3 => [moe], 5 => [innie], 6 => [minnie]}␤»
  ```
  
  We are declaring the scope of `%words{Int}` on the fly, with keys that are actually integers; it gets created with the result of the classification.
  