Skip to content

Commit f8bf712

Browse files
committed
Checks out for #2277, reflows meanwhile
1 parent 76f3372 commit f8bf712

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

doc/Type/Bag.pod6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ This method is inherited from L<Any|/type/Any#routine_reverse>, however,
110110
C<Mix>es do not have an inherent order and you should not trust it
111111
returning a consistent output.
112112
113-
=head1 See Also
113+
=head1 See also
114114
115115
L<Sets, Bags, and Mixes|/language/setbagmix>
116116

doc/Type/Mix.pod6

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
77
class Mix does Mixy { }
88
9-
A C<Mix> is an immutable mix, meaning a collection of distinct elements in no
10-
particular order that each have a real-number weight assigned to them. (For
11-
I<mutable> mixes, see L<MixHash> instead.)
9+
A C<Mix> is an immutable mix, meaning a collection of distinct elements
10+
in no particular order that each have a real-number weight assigned to
11+
them. (For I<mutable> mixes, see L<MixHash> instead.)
1212
1313
C<Mix>es are often used for performing weighted random selections - see
1414
L<.roll|roll>.
1515
16-
Objects/values of any type are allowed as mix elements. Within a C<Mix>, items
17-
that would compare positively with the L<===> operator are considered the same
18-
element, with a combined weight.
16+
Objects/values of any type are allowed as mix elements. Within a C<Mix>,
17+
items that would compare positively with the L<===> operator are
18+
considered the same element, with a combined weight.
1919
2020
=begin code
2121
my $recipe = (butter => 0.22, sugar => 0.1,
@@ -28,8 +28,8 @@ say $recipe.total; # OUTPUT: «0.615␤»
2828
=end code
2929
3030
C<Mix>es can be treated as object hashes using the C<{ }> postcircumfix
31-
operator, which returns the corresponding numeric weight for keys that are
32-
elements of the mix, and C<0> for keys that aren't:
31+
operator, which returns the corresponding numeric weight for keys that
32+
are elements of the mix, and C<0> for keys that aren't:
3333
3434
my $recipe = (butter => 0.22, sugar => 0.1,
3535
flour => 0.275, sugar => 0.02).Mix;
@@ -39,21 +39,22 @@ elements of the mix, and C<0> for keys that aren't:
3939
4040
=head1 Creating C<Mix> objects
4141
42-
C<Mix>es can be composed using the L<mix|#sub mix> subroutine (or C<Mix.new>,
43-
for which it is a shorthand). Any positional parameters, regardless of their
44-
type, become elements of the mix - with a weight of C<1> for each time the
45-
parameter occurred:
42+
C<Mix>es can be composed using the L<mix|#sub mix> subroutine (or
43+
C<Mix.new>, for which it is a shorthand). Any positional parameters,
44+
regardless of their type, become elements of the mix - with a weight of
45+
C<1> for each time the parameter occurred:
4646
4747
my $n = mix "a", "a", "b" => 0, "c" => 3.14;
4848
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Pair) (Pair))␤»
4949
say $n.pairs; # OUTPUT: «(a => 2 (c => 3.14) => 1 (b => 0) => 1)␤»
5050
51-
Alternatively, the C<.Mix> coercer (or its functional form, C<Mix()>) can be
52-
called on an existing object to coerce it to a C<Mix>. Its semantics depend on
53-
the type and contents of the object. In general it evaluates the object in list
54-
context and creates a mix with the resulting items as elements, although for
55-
Hash-like objects or Pair items, only the keys become elements of the mix, and
56-
the (cumulative) values become the associated numeric weights:
51+
Alternatively, the C<.Mix> coercer (or its functional form, C<Mix()>)
52+
can be called on an existing object to coerce it to a C<Mix>. Its
53+
semantics depend on the type and contents of the object. In general it
54+
evaluates the object in list context and creates a mix with the
55+
resulting items as elements, although for Hash-like objects or Pair
56+
items, only the keys become elements of the mix, and the (cumulative)
57+
values become the associated numeric weights:
5758
5859
my $n = ("a", "a", "b" => 0, "c" => 3.14).Mix;
5960
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))␤»
@@ -82,27 +83,33 @@ Defined as:
8283
8384
method Bag (--> Bag:D)
8485
85-
Coerces the C<Mix> to a L«C<Bag>|/type/Bag». The weights are convert to L«C<Int>|/type/Int»,
86-
which means the number of keys in the resulting C<Bag> can be fewer than in the
87-
original C<Mix>, if any of the weights are negative or truncate to zero.
86+
Coerces the C<Mix> to a L«C<Bag>|/type/Bag». The weights are convert to
87+
L«C<Int>|/type/Int», which means the number of keys in the resulting
88+
C<Bag> can be fewer than in the original C<Mix>, if any of the weights
89+
are negative or truncate to zero.
8890
8991
=head2 method BagHash
9092
9193
Defined as:
9294
9395
method BagHash (--> BagHash:D)
9496
95-
Coerces the C<Mix> to a L«C<BagHash>|/type/BagHash». The weights are convert to L«C<Int>|/type/Int»,
96-
which means the number of keys in the resulting C<BagHash> can be fewer than in the
97-
original C<Mix>, if any of the weights are negative or truncate to zero.
97+
Coerces the C<Mix> to a L«C<BagHash>|/type/BagHash». The weights are
98+
convert to L«C<Int>|/type/Int», which means the number of keys in the
99+
resulting C<BagHash> can be fewer than in the original C<Mix>, if any of
100+
the weights are negative or truncate to zero.
98101
99102
=head2 method reverse
100103
101-
I<Note>: This method is inherited from L<Any|/type/Any#routine_reverse>, however, C<Mix>es do not have an inherent order and you should not trust it returning a consistent output.
104+
I<Note>: This method is inherited from L<Any|/type/Any#routine_reverse>,
105+
however, C<Mix>es do not have an inherent order and you should not trust
106+
it returning a consistent output.
102107
103108
=head2 Note on order
104109
105-
Same as the other elements in the L<Bag/Mix suite|/language/setbagmix>, order is not guaranteed or consistent and you shouldn't rely on methods like C<reverse> above returning always the same result.
110+
Same as the other elements in the L<Bag/Mix suite|/language/setbagmix>,
111+
order is not guaranteed or consistent and you shouldn't rely on methods
112+
like C<reverse> above returning always the same result.
106113
107114
=head1 See Also
108115

0 commit comments

Comments
 (0)