Skip to content

Commit

Permalink
make .map more Perlish, and fix complaints by pmichaud++
Browse files Browse the repository at this point in the history
In particular:
 * removed some type constraints on invocants
 * .map should work when lists become lazy, ie not querying @list.end
  • Loading branch information
moritz committed Mar 8, 2009
1 parent a7214ac commit 167e251
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/setting/Any-list.pm
Expand Up @@ -5,25 +5,22 @@ class Any is also {
}
}

our List of Capture multi method map(List @values: Code *&expr) {
gather {
my $i = 0;
while ($i <= @values.end) {
my @args;
@args.push(($i <= @values.end) ?? @values[$i++] !! undef)
for (1..&expr.arity || 1);

take &expr(|@args);
our List multi method map(Code *&expr) {
return gather {
my $arity = &expr.arity || 1;
my @args;
for self.list {
@args.push($_);
if (@args == $arity) {
take &expr(|@args);
@args = ();
}
}
}
}

our List of Capture multi method map($value: Code *&expr) {
($value,).map: &expr
}

# RT #63700 - parse failed on &infix:<cmp>
our Array multi method min( $values: Code $by = sub { $^a cmp $^b } ) {
our Array multi method min( $values: Code $by = sub { $^a cmp $^b } ) {
my @list = $values.list;
return +Inf unless @list.elems;
my $res = @list.shift;
Expand Down Expand Up @@ -58,8 +55,7 @@ our List multi pairs(@values, *@indices) {
@values.pairs(@indices)
}

our List multi min(*@values) {
my $by = @values[0] ~~ Code ?? shift @values !! sub { $^a cmp $^b };
our List multi min($by, *@values) {
@values.min($by);
}

Expand Down

0 comments on commit 167e251

Please sign in to comment.