In Hash§
See primary documentation in context for method categorize-list
multi method categorize-list(, *, : --> Hash)multi method categorize-list(, *, : --> Hash)multi method categorize-list(, *, : --> Hash)
Populates a Hash
by classifying the possibly-empty @list
of values using the given mapper
, optionally altering the values using the :&as
Callable
. The @list
cannot be lazy.
The mapper can be a Callable
that takes a single argument, an Associative
, or an Iterable
. With Associative
and an Iterable
mappers, the values in the @list
represent the key and index of the mapper's value respectively. A 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.
In role Baggy§
See primary documentation in context for method categorize-list
multi method categorize-list(, * --> Baggy)multi method categorize-list(, * --> Baggy)multi method categorize-list(, * --> Baggy)
Populates a mutable Baggy
by categorizing the possibly-empty @list
of values using the given mapper
. The @list
cannot be lazy.
say BagHash.new.categorize-list:, ^10;# OUTPUT: BagHash(largish(4) even(5) non-prime(6) prime(4) odd(5))my = :sugar<sweet white>, :lemon<sour>, :cake('sweet', 'is-a-lie');say MixHash.new.categorize-list: , <sugar lemon cake>;# OUTPUT: MixHash(is-a-lie sour white sweet(2))
The mapper can be a Callable
that takes a single argument, an Associative
, or an Iterable
. With Associative
and an Iterable
mappers, the values in the @list
represent the key and index of the mapper's value respectively. A 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
's .categorize-list
, returning a list of Iterables
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.