In Junction§
See primary documentation in context for method defined.
multi method defined(Junction:D:)
Checks for definedness instead of Boolean values.
say ( 3 | Str).defined ; # OUTPUT: «True» say (one 3, Str).defined; # OUTPUT: «True» say (none 3, Str).defined; # OUTPUT: «False»
Failures are also considered non-defined:
my $foo=Failure.new; say (one 3, $foo).defined; # OUTPUT: «True»
Since 6.d, this method will autothread.
In Mu§
See primary documentation in context for routine defined.
multi method defined( --> Bool:D) multi defined(Mu --> Bool:D)
Returns False on a type object, and True otherwise. (The sub evaluates its argument, and the method its invocant.)
say Int.defined; # OUTPUT: «False» say 42.defined; # OUTPUT: «True»
A few types (like Failure) override defined to return False even for instances:
sub fails() { fail 'oh noe' }; say fails().defined; # OUTPUT: «False»
In Failure§
See primary documentation in context for method defined.
multi method defined(Failure:D: --> Bool:D)
Returns False (failures are officially undefined), and marks the failure as handled.
sub f() { fail }; my $v = f; say $v.handled; # OUTPUT: «False» say $v.defined; # OUTPUT: «False» say $v.handled; # OUTPUT: «True»