Skip to content

Commit

Permalink
Improves documentation and examples for Mix
Browse files Browse the repository at this point in the history
The example for the second case was reproduced over and over, but it
didn't behave the same in the first example, so I have changed it to a
new one and explains behavior. Also adds another example for `is`,
which uses a different mechanism, `STORE`

Closes #2459
  • Loading branch information
JJ committed Nov 15, 2018
1 parent 39d580d commit ff2e2bc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions doc/Type/Mix.pod6
Expand Up @@ -44,9 +44,10 @@ C<Mix.new>, for which it is a shorthand). Any positional parameters,
regardless of their type, become elements of the mix - with a weight of
C<1> for each time the parameter occurred:
my $n = mix "a", "a", "b" => 0, "c" => 3.14;
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Pair) (Pair))␤»
say $n.pairs; # OUTPUT: «(a => 2 (c => 3.14) => 1 (b => 0) => 1)␤»
my $n = mix "a", "a", "b" => 0, 3.14, π, π; # The Pair is a single element
say $n.keys.map: *.^name; # OUTPUT: «(Rat Pair Num Str)␤»
say $n.pairs;
# OUTPUT: «(3.14 => 1 (b => 0) => 1 3.141592653589793 => 2 a => 2)␤»
Alternatively, the C<.Mix> coercer (or its functional form, C<Mix()>)
can be called on an existing object to coerce it to a C<Mix>. Its
Expand All @@ -60,6 +61,15 @@ values become the associated numeric weights:
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))␤»
say $n.pairs; # OUTPUT: «(a => 2 c => 3.14)␤»
Elements with a 0 value, as C<b> above, are simply eliminated from the C<Mix>.
Alternatively, since C<Mix>es are L<Associative>, we can use the C<%> sigil to
declare them; in that case, we can employ C<is> to declare their type:
my %n is Mix = ("a", "a", "b" => 0, "c" => 3.14);
say %n.^name; # OUTPUT: «Mix␤»
say %n; # OUTPUT: «Mix(a(2), c(3.14))␤»
=head1 Operators
C<Mix>es can use all kind of set operators returning either C<Bool> or
Expand Down

0 comments on commit ff2e2bc

Please sign in to comment.