Skip to content

Commit d5d51fe

Browse files
committed
Clarifies relationship between does and isa and ~~
This closes #1556. Actually erases the equivalence between isa and ~~, because it's simply not true.
1 parent bf32bec commit d5d51fe

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

doc/Type/Mu.pod6

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ invokes the C<.defined> method on the object and returns its result.
4848
multi method isa(Mu $type --> Bool:D)
4949
multi method isa(Str:D $type --> Bool:D)
5050
51-
Returns C<True> if the invocant is an instance of class C<$type>, a subset type or a derived class (through inheritance) of C<$type>.
51+
Returns C<True> if the invocant is an instance of class C<$type>, a subset type or a derived class (through inheritance) of C<$type>. Unlike L<C<does>|/routine/does#(Mu)_routine_does>, which includes roles.
5252
5353
my $i = 17;
5454
say $i.isa("Int"); # OUTPUT: «True␤»
5555
say $i.isa(Any); # OUTPUT: «True␤»
56+
role Truish {};
57+
my $but-true = 0 but Truish;
58+
say $but-true.^name; # OUTPUT: «Int+{Truish}␤»
59+
say $but-true.does(Truish); # OUTPUT: «True␤»
60+
say $but-true.isa(Truish); # OUTPUT: «False␤»
5661
57-
A more idiomatic way to do this is to use the smartmatch operator L<~~|/routine/~~> instead.
58-
59-
my $s = "String";
60-
say $s ~~ Str; # OUTPUT: «True␤»
6162
6263
=head2 routine does
6364
@@ -70,6 +71,10 @@ Returns C<True> if and only if the invocant conforms to type C<$type>.
7071
say $d.does(Any); # True (Date is a subclass of Any)
7172
say $d.does(DateTime); # False (Date is not a subclass of DateTime)
7273
74+
Unlike L<C<isa>|https://docs.perl6.org/routine/isa#(Mu)_routine_isa>, which returns C<True> only for superclasses, C<does> includes both superclasses and roles.
75+
76+
say $d.isa(Dateish); # OUTPUT: «False␤»
77+
7378
Using the smart match operator L<~~|/routine/~~> is a more idiomatic alternative.
7479
7580
my $d = Date.new('2016-06-03');

0 commit comments

Comments
 (0)