Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
the initial value is the first argument
  • Loading branch information
kraih committed Aug 4, 2014
1 parent 3c18fa3 commit a613a7d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Collection.pm
Expand Up @@ -74,7 +74,7 @@ sub pluck {
}

sub reduce {
my ($self, $cb) = (shift, shift);
my ($self, $cb) = (shift, pop);
return List::Util::reduce(sub { $a->$cb($b) }, @_, @$self);
}

Expand Down Expand Up @@ -259,7 +259,7 @@ results.
=head2 reduce
my $result = $collection->reduce(sub {...});
my $result = $collection->reduce(sub {...}, $initial);
my $result = $collection->reduce($initial => sub {...});
Reduce elements in collection with callback, the first element will be used as
initial value if none has been provided.
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/collection.t
Expand Up @@ -115,7 +115,7 @@ is $collection->size, 5, 'right size';
# reduce
$collection = c(2, 5, 4, 1);
is $collection->reduce(sub { shift() + shift() }), 12, 'right result';
is $collection->reduce(sub { shift() + shift() }, 5), 17, 'right result';
is $collection->reduce(5 => sub { shift() + shift() }), 17, 'right result';
is c()->reduce(sub { shift() + shift() }), undef, 'no result';

# sort
Expand Down

0 comments on commit a613a7d

Please sign in to comment.