- or download this
#!/usr/bin/perl
use warnings;
use strict;
- or download this
package Sequences;
...
sub seqsub(&) {
Sequences->new(@_);
}
- or download this
sub seq {
my ($i, $elems) = (0, \@_);
...
: do { $i = 0; () };
}
}
- or download this
my $abcees = seq("a", "b", "c");
...
$abcees->(); # ("c")
$abcees->(); # ( )
# ... the cycle repeats ...
- or download this
use Data::Dumper;
...
}
$seq;
}
- or download this
enumerate( $abcees );
# 0 => a
# 1 => b
# 2 => c
- or download this
$abcees->enumerate;
# 0 => a
# 1 => b
# 2 => c
- or download this
sub seq_prod2 {
my ($s, $t) = @_;
...
( @sval, @tval );
}
};
- or download this
my $one_two_threes = seq( 1 .. 3 );
...
# 6 => c 1
# 7 => c 2
# 8 => c 3
- or download this
use List::Util qw( reduce );
sub seq_prod {
reduce { seq_prod2($a,$b) } @_ ;
}
- or download this
my $you_and_mees = seq( "you", "me" );
...
# 15 => c 2 me
# 16 => c 3 you
# 17 => c 3 me
- or download this
my (@alist, @blist, @clist);
# ... initialize arrays with values ...
...
}
}
}
- or download this
my $combined_sequence =
seq_prod( seq(@alist), seq(@blist), seq(@clist) );
...
while ( my ($a, $b, $c) = $combined_sequence->() ) {
# do something with ($a, $b, $c)
}
- or download this
sub seqs {
map seq(@$_), @_;
...
sub seq_from_spec {
seq_prod( seqs(@_) );
}
- or download this
sub nary_digits {
my ($base, $digits) = @_;
...
# 5 => 1 0 1
# 6 => 1 1 0
# 7 => 1 1 1
- or download this
# seq_from_spec([1..3]) === seq(1..3)
# seq_from_spec([1..3],[4,5]) === seq(1..3) x seq(4,5)
# seq_from_spec(\(@a,@b,...)) === seq(@a) x seq(@b) x ...
- or download this
sub seq_foreach {
my ($seq, $fn) = @_;
...
}
$seq;
}
- or download this
$abcees->seq_foreach( sub { print "@_\n"; } );
# a
# b
# c
- or download this
sub seq_foreach_from_spec {
my ($spec, $fn) = @_;
seq_foreach( seq_from_spec( @$spec ), $fn );
}
- or download this
seq_foreach_from_spec( [\(@alist, @blist, @clist)], sub {
my ($a, $b, $c) = @_;
# do something with $a, $b, $c, ...
});
- or download this
sub seq_filter {
my ($seq, $filter_fn) = @_;
...
return @val;
}
}
- or download this
sub odds_up_to {
my $maximum = shift;
...
# 2 => 5
# 3 => 7
# 4 => 9
- or download this
sub seq_map {
my ($seq, $fn) = @_;
...
@val ? $fn->(@val) : ();
}
}
- or download this
sub evens_up_to {
odds_up_to( $_[0] + 1 )
...
# 3 => 6
# 4 => 8
# 5 => 10
- or download this
sub min_length_combinations {
my ($min_length, @inputs) = @_;
...
->seq_map( sub { [ map @$_, @_ ] } )
->seq_filter( sub { @{$_[0]} >= $min_length } )
}
- or download this
min_length_combinations(
4, map [split//], qw( abc de fgh i jk l m )
...
# 863 => ['c','e','h','i','k','m']
# 864 => ['c','e','h','i','k','l']
# 865 => ['c','e','h','i','k','l','m']
- or download this
sub seq_series {
my $seqs = seq( @_ ); # seq of seqs (!)
...
# 3 => 1
# 4 => 2
# 5 => 3
- or download this
sub seq_reset {
my $seq = shift;
...
return @outvals;
}
}
- or download this
seq_zip( $abcees, $one_two_threes )->enumerate;
...
# 0 => a 1 you
# 1 => b 2 me
- or download this
sub seq_zip_with {
my $zipper_fn = shift;
seq_map( seq_zip(@_), $zipper_fn );
}
- or download this
# some math helpers
...
# 2 => 24
# 3 => 60
# 4 => 120
- or download this
my @site1 = qw( AATKKM aatkkm );
my @site2 = qw( GGGGGG gggggg );
...
# 'A g' => 2, 'M G' => 1, 'k g' => 2, 'k G' => 2,
# 'T G' => 1, 'a G' => 2, 'm G' => 1, 't G' => 1,
# 'K g' => 2, 'M g' => 1, 't g' => 1, 'T g' => 1 }
- or download this
sub seq_values {
my $seq = shift;
...
seq_foreach( $seq, sub { push @values, @_ } );
return @values;
}
- or download this
print Dumper( [ seq(1..3)->seq_values ] ), "\n";
# [[1],[2],[3]]
print Dumper( [ seq(1..3)->seq_values_scalar ] ), "\n";
# [1,2,3]
- or download this
sub matrix_transpose {
my $rows = shift;
...
print Dumper( matrix_transpose( $matrix ) ), "\n";
# [ [0,2,4]
# , [1,3,5] ]
- or download this
sub seq_fold {
my ($seq, $fn) = @_;
...
}
wantarray ? @accum : $accum[0];
}
- or download this
sub dot_product {
seq_zip_with( \&product, seqs(@_) )
...
print dot_product( [1,1,1], [1,2,3] ), "\n";
# 6