As Haakon Hegland has already pointed out, this is not what you should do:
Connections are intended to be used as helpers in a boolean context; transition introspection is not supported. If you feel the urge to explore the connection, use Set or the type associated with it instead.
- docs.perl6.org/type/Junction
However, this is possible.
First, you can use authothreading (i.e., automatically evaluate each branch branch when passing a function that expects an argument of type Any ):
sub unjunc(Junction $j) { gather -> Any $_ { .take }.($j); }
Secondly, you can push the guts out and manually extract the values:
sub unjunc(Junction $j) { multi extract(Any $_) { .take } multi extract(Junction $_) { use nqp; my $list := nqp::getattr($_, Junction, '$!storage'); my int $elems = nqp::elems($list); loop (my int $i = 0; $i < $elems; $i = $i + 1) { extract nqp::atpos($list, $i); } } gather extract $j; }
If your connection is not recursive (i.e. does not contain other connections that you want to smooth out), the latter approach can be simplified:
my $j := 1|2|3; say nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', nqp::getattr($j, Junction, '$!storage'));
Christoph
source share