Skip to content

Commit

Permalink
Document Failure.self
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Jun 8, 2017
1 parent 057c651 commit 457be16
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions doc/Type/Failure.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ Returns the L<Exception> object that the failure wraps.
put "$ex.^name(): $ex";
# OUTPUT: «X::AdHoc: Failed␤»
=head2 method self
Defined as:
method exception(Failure:D: --> Failure:D)
If the invocant is a L<handled> C<Failure>, returns it as is.
If not not handled, throws its L<Exception>. Since
L<Mu> type L«provides C<.self>|/type/Mu#method_self» for every
class, calling this method is a handy way to explosively
filter out Failures:
my $num1 = '♥'.Int;
# $num1 now contains a Failure object, which may not be desirable
my $num2 = '♥'.Int.self;
# .self method call on Failure causes an exception to be thrown
my $num3 = '42'.Int.self;
# Int type has a .self method, so here $num3 has `42` in it
(my $stuff = '♥'.Int).so;
say $stuff.self; # OUTPUT: «(HANDLED) Cannot convert string to number…»
# Here, Failure is handled, so .self just returns it as is
=head2 method Bool
Defined as:
Expand Down

1 comment on commit 457be16

@rafaelschipiura
Copy link
Contributor

@rafaelschipiura rafaelschipiura commented on 457be16 Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Int type has a .self method, so here $num3 has 42 in it

Maybe make it clear this is the case for Mu, not just Int?

Otherwise people might think they need to check if the class implements this method, instead of just assuming it's there because Mu is in everything.

Please sign in to comment.