Skip to content

Commit ff2e2bc

Browse files
committed
Improves documentation and examples for Mix
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
1 parent 39d580d commit ff2e2bc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

doc/Type/Mix.pod6

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ C<Mix.new>, for which it is a shorthand). Any positional parameters,
4444
regardless of their type, become elements of the mix - with a weight of
4545
C<1> for each time the parameter occurred:
4646
47-
my $n = mix "a", "a", "b" => 0, "c" => 3.14;
48-
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Pair) (Pair))␤»
49-
say $n.pairs; # OUTPUT: «(a => 2 (c => 3.14) => 1 (b => 0) => 1)␤»
47+
my $n = mix "a", "a", "b" => 0, 3.14, π, π; # The Pair is a single element
48+
say $n.keys.map: *.^name; # OUTPUT: «(Rat Pair Num Str)␤»
49+
say $n.pairs;
50+
# OUTPUT: «(3.14 => 1 (b => 0) => 1 3.141592653589793 => 2 a => 2)␤»
5051
5152
Alternatively, the C<.Mix> coercer (or its functional form, C<Mix()>)
5253
can be called on an existing object to coerce it to a C<Mix>. Its
@@ -60,6 +61,15 @@ values become the associated numeric weights:
6061
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))␤»
6162
say $n.pairs; # OUTPUT: «(a => 2 c => 3.14)␤»
6263
64+
Elements with a 0 value, as C<b> above, are simply eliminated from the C<Mix>.
65+
66+
Alternatively, since C<Mix>es are L<Associative>, we can use the C<%> sigil to
67+
declare them; in that case, we can employ C<is> to declare their type:
68+
69+
my %n is Mix = ("a", "a", "b" => 0, "c" => 3.14);
70+
say %n.^name; # OUTPUT: «Mix␤»
71+
say %n; # OUTPUT: «Mix(a(2), c(3.14))␤»
72+
6373
=head1 Operators
6474
6575
C<Mix>es can use all kind of set operators returning either C<Bool> or

0 commit comments

Comments
 (0)