This implementation is much clearer (assuming you know concatmap).seq_from_spec( \(@site1, @site2) ) ->seq_concatmap( sub { seq_zip(map seq(split//), @_) } ) ->seq_foreach( sub { $counts{"@_"}++ } );
Concatmap combines concat and map; it maps a sequence to a sequence of sequences, whose values are then concatenated to yield the output sequence. For example:
sub upto { 1 .. $_[0] } sub supto { seq(upto(@_)); } seq(1..3) -> seq_map(\&upto) -> enumerate; # 0 => 1 # 1 => 1 2 # 2 => 1 2 3 seq(1..3) -> seq_map(\&supto) -> seq_concat -> enumerate; # 0 => 1 # 1 => 1 # 2 => 2 # 3 => 1 # 4 => 2 # 5 => 3 seq(1..3) -> seq_concatmap(\&supto) -> enumerate; # 0 => 1 # 1 => 1 # 2 => 2 # 3 => 1 # 4 => 2 # 5 => 3
Cheers,
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
In reply to Re^2: A mini-language for sequences (part 1)
by tmoertel
in thread A mini-language for sequences (part 1)
by tmoertel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |