mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

->reduce examples broken? #44

Closed pipcet closed 6 years ago

pipcet commented 6 years ago

This is a documentation bug. The POD for Mojo::Pg::Results contains these examples:

say $results->arrays->reduce(sub { $a->[3] + $b->[3] });
say $results->hashes->reduce(sub { $a->{money} + $b->{money} });

which fail to work if there are more than two elements in $results. The proper code for the second example would be:

say $results->hashes->reduce(sub { { money => $a->{money} + $b->{money} } })->{money};
pipcet commented 6 years ago

Alternatively,

say $results->hashes->reduce(sub { $a + $b->{money} }, 0);

That's even shorter than the original code!

kraih commented 6 years ago

Thanks, you are absolutely correct, that was a typo.