Skip to content

Commit 0728c55

Browse files
committed
Document Pair.ACCEPTS
Fixes #1235
1 parent 96993c6 commit 0728c55

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/Type/Pair.pod6

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ Any variable can be turned into a C<Pair> of its name and its value.
5050
5151
=head1 Methods
5252
53+
=head2 method ACCEPTS
54+
55+
Defined as:
56+
57+
multi method ACCEPTS(Pair:D $: %topic)
58+
multi method ACCEPTS(Pair:D $: Pair:D $topic)
59+
multi method ACCEPTS(Pair:D $: Mu $topic)
60+
61+
If C<topic> is an L<Associative>, looks up the value using invocant's key in
62+
it and checks invocant's value C<.ACCEPTS> that value:
63+
64+
say %(:42a) ~~ :42a; # OUTPUT: «True␤»
65+
say %(:42a) ~~ :10a; # OUTPUT: «False␤»
66+
67+
If C<topic> is another L<Pair>, checks the invocant's value C<.ACCEPTS> the
68+
C<topic's> value. Note that the keys are not considered and can be different:
69+
70+
say :42a ~~ :42a; # OUTPUT: «True␤»
71+
say :42z ~~ :42a; # OUTPUT: «True␤»
72+
say :10z ~~ :42a; # OUTPUT: «False␤»
73+
74+
If C<topic> is any other value, uses the invocant's key as the name of the
75+
method to call on C<topic> and check's its L«C<.Bool>|/routine/Bool» is the same
76+
as C<.Bool> of the invocant's value. This form can be used to check L<Bool> values
77+
of multiple methods on the same object, such as L<IO::Path>, by using
78+
L<Junctions|/type/Junction>:
79+
80+
say "foo" .IO ~~ :f & :rw; # OUTPUT: «False␤»
81+
say "/tmp".IO ~~ :!f; # OUTPUT: «True␤»
82+
say "." .IO ~~ :f | :d; # OUTPUT: «True␤»
83+
5384
=head2 method antipair
5485
5586
Defined as:

0 commit comments

Comments
 (0)