Skip to content

Commit 08b0f48

Browse files
committed
Adds op examples, refs #2277
1 parent f8bf712 commit 08b0f48

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

doc/Type/Bag.pod6

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ values become the associated integer weights:
6565
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))␤»
6666
say $n.values.perl; # OUTPUT: «(1, 4).Seq␤»
6767
68-
Furthermore, you can get a C<Bag> by using bag operators (see next section) on
69-
objects of other types such as L<List>, which will internally call C<.Bag>
70-
on them before performing the operation. Be aware of the tight precedence of
71-
those operators though, which may require you to use parentheses around arguments:
68+
Furthermore, you can get a C<Bag> by using bag operators (see next
69+
section) on objects of other types such as L<List>, which will
70+
internally call C<.Bag> on them before performing the operation. Be
71+
aware of the tight precedence of those operators though, which may
72+
require you to use parentheses around arguments:
7273
7374
say (1..5) (+) 4; # OUTPUT: «bag(1, 2, 3, 4(2), 5)␤»
7475
7576
=head1 Operators
7677
77-
Perl 6 provides common set and bag operators, which can take C<Bag>s (or any
78-
other collections) as input, and return result as C<Bool>, C<Set> or C<Bag>
79-
values. For example:
78+
Perl 6 provides common set and bag operators, which can take C<Bag>s (or
79+
any other collections) as input, and return result as C<Bool>, C<Set> or
80+
C<Bag> values. For example:
8081
8182
=begin code
8283
my ($a, $b) = bag(2, 2, 4), bag(2, 3, 3, 4);

doc/Type/Mix.pod6

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,27 @@ values become the associated numeric weights:
6262
6363
=head1 Operators
6464
65-
=for comment
66-
TODO: Expand this section (using the corresponding section in lib/Type/Bag.pod
67-
as a guide) after ab5tract's set/bag/mix operator redesign.
65+
C<Mix>es can use all kind of set operators returning either C<Bool> or other C<Mix>es:
6866
69-
See L<Set/Bag Operators|/language/setbagmix#Set/Bag_operators> for a complete list of set and bag operators
70-
with detailed explanations.
67+
=begin code
68+
my $this-mix = (sugar => ⅓, spice => ¼, all-things-nice => ¾);
69+
my $that-mix = ( sugar => 1, spice => 2);
70+
71+
say $that-mix (<) $this-mix; # OUTPUT: «True␤»
72+
say $that-mix (^) $this-mix; # OUTPUT: «set(all-things-nice)␤»
73+
say $that-mix (+) $this-mix; # OUTPUT: «Bag(spice(2), sugar)␤»
74+
=end code
75+
76+
With their equivalent Unicode operators:
77+
=begin code :preamble<my ($this-mix, $that-mix);
78+
say $that-mix ⊂ $this-mix; # OUTPUT: «True␤»
79+
say $that-mix ⊖ $this-mix; # OUTPUT: «set(all-things-nice)␤»
80+
say $that-mix ⊎ $this-mix; # OUTPUT: «Bag(spice(2), sugar)␤»
81+
=end code
82+
83+
84+
See L<Set/Bag Operators|/language/setbagmix#Set/Bag_operators> for a
85+
complete list of set and bag operators with detailed explanations.
7186
7287
=head2 sub mix
7388

0 commit comments

Comments
 (0)