Building Junctions from Junctions

2008-06-23 Thread Ovid
Hi all,

I use Perl6::Junction in Perl 5 and recently the author implemented the
"values" method on junctions.  I needed this because I sometimes find
that I need to do something conceptually similar to this:

  my $number = any( 0 .. 19 );
  while ($number->values) {
my $rand int(rand(20));
if ( $number == $random_number ) {

  # handle some task and discard the number
  $number = any( grep { $_ != $rand } $number->values );
}
  }

In other words, sometimes I have code which receives a junction and
needs to provide a new junction based on the values of the old
junction, but with some values removed.

How do I do that in Perl 6?  I can't see that in the docs.  Clearly we
don't this to be done destructively as I suspect this will break
autothreading, but building new junctions based on old junctions seems
reasonable.

Cheers,
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Personal blog- http://publius-ovidius.livejournal.com/
Tech blog- http://use.perl.org/~Ovid/journal/
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6 
Official Parrot Wiki - http://www.perlfoundation.org/parrot


Re: Building Junctions from Junctions

2008-06-23 Thread Jon Lang
I'd say that this ought to be implemented using :v (as in, 'values';
cf. :k, :kv, and :p for lists and hashes): this should let you look at
the values within the Junction as if they were merely a list of
values, at which point you can construct a new Junction from them.

-- 
Jonathan "Dataweaver" Lang