Populates a mutableBaggy by classifying the possibly-empty @list of values using the given mapper. The @list cannot be lazy.

sayBagHash.new.classify-list:{$_%%2??'even'!!'odd'}, ^10;

# OUTPUT: BagHash.new(even(5), odd(5))

my@mapper=<zero one two three four five>;

sayMixHash.new.classify-list:@mapper, 1, 2, 3, 4, 4, 6;

# OUTPUT: MixHash.new((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.

Populates a Hash by classifying the possibly-empty @list of values using the given mapper, optionally altering the values using the :&asCallable. 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 multi-level classification mode, each mapper's value is an Iterable that represents a tree of hash keys to classify @list's item under:

say%.classify-list:{

[

(.is-prime??'prime'!!'non-prime'),

($_%%2??'even'!!'odd' ),

]

}, ^10;

# OUTPUT:

# {

# non-prime => {

# even => [0 4 6 8],

# odd => [1 9]

# },

# prime => {

# even => [2],

# odd => [3 5 7]

# }

# }

In the case we are using Iterables and not Callables, each of those Iterables must have the same number of elements, or the method will throw an exception. This restriction exists to avoid conflicts when the same key is a leaf of one value's classification but a node of another value's classification.

Every element of the array represents a different level in the tree, with the elements of the list that is being mapped used as index, and the elements of the mapper array used as keys to the different levels. So 0 selects the first sub-array and then the subsequent levels are built by running over the rest of the elements of that sub-array.