In Hash§
See primary documentation in context for method classify-list
multi method classify-list(, *, : --> Hash)multi method classify-list(, *, : --> Hash)multi method classify-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
; this Callable
is guaranteed to be called only once per item. 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 classify-list
multi method classify-list(, * --> Baggy)multi method classify-list(, * --> Baggy)multi method classify-list(, * --> Baggy)
Populates a mutable Baggy
by classifying the possibly-empty @list
of values using the given mapper
. The @list
cannot be lazy.
say BagHash.new.classify-list: , ^10;# OUTPUT: BagHash(even(5) odd(5))my = <zero one two three four five>;say MixHash.new.classify-list: , 1, 2, 3, 4, 4, 6;# OUTPUT: MixHash((Any) two three four(2) one)
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 the key of the Baggy
that will be incremented by 1
. See .categorize-list
if you wish to classify an item into multiple categories at once.
Note: unlike the Hash
's .classify-list
, returning an Iterable
mapper's value will throw, as Baggy
types do not support nested classification. For the same reason, Baggy
's .classify-list
does not accept :&as
parameter.