diff --git a/doc/Type/Junction.pod6 b/doc/Type/Junction.pod6 index d309ee472..b12fdc997 100644 --- a/doc/Type/Junction.pod6 +++ b/doc/Type/Junction.pod6 @@ -33,6 +33,8 @@ junctions, you use the string that represents the type followed by any object, or else call L|/routine/all>, L|/routine/none> or L|/routine/one> on the object. + say so 3 == (1..30).one;# OUTPUT: «True␤» + Autothreading happens when a junction is bound to a parameter of a code object that doesn't accept values of type C. Instead of producing an error, the signature binding is repeated for each value of the junction. @@ -50,10 +52,10 @@ C. The C conditional evaluates the junction in boolean context, which collapses it to C. So the code prints C. The type of a C does I affect the number of items in the -resultant C after autothreading. For example, using a L -C during L key lookup, still results in a C -with several items. It is only in boolean context would the type of the -C come into play: +resultant C after autothreading. For example, using a +L C during L key lookup, still +results in a C with several items. It is only in boolean context would +the type of the C come into play: my %h = :42foo, :70bar; say %h{one }:exists; # OUTPUT: «one(True, False)␤» @@ -143,32 +145,33 @@ are concerned: my $j = +any "not a number", "42", "2.1"; (gather $j».take).grep(Numeric).say; # OUTPUT: «(42 2.1)␤» -Above, we've used prefix C<+> operator on a L to coerce the strings -inside of it to L. Since the operator returns a L when -L that doesn't contain a number gets coerced to C, one of the -elements in the C is a C, but same C rules as normal -apply and the C doesn't explode just because it's in a C, and -we can L«C<.grep>|/routine/grep» it out. The exception I be thrown, -if you try to use the C as a value—just like were this C on -its own and not part of the C: +Above, we've used prefix C<+> operator on a L to coerce +the strings inside of it to L. Since the operator returns +a L when L that doesn't contain a number +gets coerced to C, one of the elements in the C is a +C, but same C rules as normal apply and the C doesn't +explode just because it's in a C, and we can L«C<.grep>|/routine/grep» +it out. The exception I be thrown, if you try to use the C as a +value—just like were this C on its own and not part of the C: my $j = +any "not a number", "42", "2.1"; try say $j == 42; $! and say "Got exception: $!.^name()"; # OUTPUT: «Got exception: X::Str::Numeric␤» Note that if an exception gets thrown when I of the values in a -L get computed, it will be thrown just as if the problematic value -were computed on its own and not with a C; you can't just compute the -values that work while ignoring exceptions: +L get computed, it will be thrown just as if the +problematic value were computed on its own and not with a C; you can't +just compute the values that work while ignoring exceptions: sub calc ($_) { die when 13 } my $j = any 1..42; say try calc $j; # OUTPUT: «Nil␤» -Only one value above causes an exception, but the result of the -L«C block|/language/exceptions#index-entry-try_blocks-try» is still a L. -A possible way around it is to cheat and evaluate the values of the C -individually and then re-create the C from the result: +Only one value above causes an exception, but the result of the L«C +block|/language/exceptions#index-entry-try_blocks-try» is still a +L. A possible way around it is to cheat and evaluate the values +of the C individually and then re-create the C from the +result: sub calc ($_) { die when 13 } my $j = any 1..42; @@ -198,9 +201,10 @@ Defined as: multi method Str(Junction:D:) -Autothreads the C<.Str> method over its elements and returns results as a L. Output -methods that use C<.Str> method (L and L) are special-cased to autothread junctions, -despite being able to accept a L type. +Autothreads the C<.Str> method over its elements and returns results as a +L. Output methods that use C<.Str> method +(L and L) are special-cased to +autothread junctions, despite being able to accept a L type. =head2 method gist