txt: ## categorize-list.md
  categorize-list
  
  Combined from primary sources listed below.
  
  # [In role Baggy](#___top "go to top of document")[§](#(role_Baggy)_method_categorize-list "direct link")
  
  See primary documentation
  [in context](/type/Baggy#method_categorize-list)
  for **method categorize-list**.
  
  ```raku
  multi method categorize-list(&mapper, *@list --> Baggy:D)
  multi method categorize-list(%mapper, *@list --> Baggy:D)
  multi method categorize-list(@mapper, *@list --> Baggy:D)
  ```
  
  Populates a *mutable* `Baggy` by categorizing the possibly-empty `@list` of values using the given `mapper`. The `@list` cannot be lazy.
  
  ```raku
  say BagHash.new.categorize-list: {
      gather {
          take 'largish' if $_ > 5;
          take .is-prime ?? 'prime' !! 'non-prime';
          take $_ %% 2   ?? 'even'  !! 'odd';
      }
  }, ^10;
  # OUTPUT: BagHash(largish(4) even(5) non-prime(6) prime(4) odd(5))
  
  my %mapper = :sugar<sweet white>, :lemon<sour>, :cake('sweet', 'is-a-lie');
  say MixHash.new.categorize-list: %mapper, <sugar lemon cake>;
  # OUTPUT: MixHash(is-a-lie sour white sweet(2))
  ```
  
  The mapper can be a [`Callable`](/type/Callable) that takes a single argument, an [`Associative`](/type/Associative), or an [`Iterable`](/type/Iterable). With [`Associative`](/type/Associative) and an [`Iterable`](/type/Iterable) mappers, the values in the `@list` represent the key and index of the mapper's value respectively. A [`Callable`](/type/Callable) mapper will be executed once per each item in the `@list`, with that item as the argument and its return value will be used as the mapper's value.
  
  The mapper's value is used as a possibly-empty list of keys of the `Baggy` that will be incremented by `1`.
  
  **Note:** unlike the [`Hash`](/type/Hash)'s `.categorize-list`, returning a list of [`Iterables`](/type/Iterable) as mapper's value will throw, as `Baggy` types do not support nested categorization. For the same reason, `Baggy`'s `.categorize-list` does not accept `:&as` parameter.
  
  # [In Hash](#___top "go to top of document")[§](#(Hash)_method_categorize-list "direct link")
  
  See primary documentation
  [in context](/type/Hash#method_categorize-list)
  for **method categorize-list**.
  
  ```raku
  multi method categorize-list(&mapper, *@list, :&as --> Hash:D)
  multi method categorize-list(%mapper, *@list, :&as --> Hash:D)
  multi method categorize-list(@mapper, *@list, :&as --> Hash:D)
  ```
  
  Populates a `Hash` by classifying the possibly-empty `@list` of values using the given `mapper`, optionally altering the values using the `:&as` [`Callable`](/type/Callable). The `@list` cannot be lazy.
  
  The mapper can be a [`Callable`](/type/Callable) that takes a single argument, an [`Associative`](/type/Associative), or an [`Iterable`](/type/Iterable). With [`Associative`](/type/Associative) and an [`Iterable`](/type/Iterable) mappers, the values in the `@list` represent the key and index of the mapper's value respectively. A [`Callable`](/type/Callable) mapper will be executed once per each item in the `@list`, with that item as the argument and its return value will be used as the mapper's value.
  