role Mixy

role Mixy does Baggy { }

A role for collections of weighted values. See Mix and MixHash. Mixy objects differ from Baggy objects in that the weights of Mixy are Reals rather than Ints.

Methods

method total

method total(--> Real)

Returns the sum of all the weights

mix('a','b','c','a','a','d').total == 6; # True
{a => 5.6, b => 2.4}.Mix.total == 8; # True

method new-fp

method new-fp(*@pairs --> Mixy)

Creates a new Mixy object from the pairs given. Where one might write:

{a => 5.6, b => 2.4}.Mix;

One could instead use:

Mix.new-fp((a => 5.6, b => 2.4));

method roll

method roll ($count = 1)

Similar to a Bag.roll, but with Real weights rather than integral ones.

Type graph

Below you should see an imgage showing the type relations for Mixy. If not, try the PNG version.

perl6-type-graph Mixy Mixy Baggy Baggy Mixy->Baggy Associative Associative QuantHash QuantHash QuantHash->Associative Baggy->QuantHash Mu Mu Any Any Any->Mu Mix Mix Mix->Mixy Mix->Any MixHash MixHash MixHash->Mixy MixHash->Any

Methods supplied by role Baggy

Mixy does role Baggy, which provides the following methods:

method grab

method grabpairs

method pick

method pickpairs

method roll

method classify-list

method categorize-list

method keys

method values

method kv

method elems

method total

method new-fp

method ACCEPTS