sum0#
Add up every value in the list, returning 0 for an empty list.
Synopsis#
my $total = sum0 @values;
my $total = sum0 (); # 0, not undef
What you get back#
The same number sum would produce, except that an empty list
yields 0 instead of undef. This is almost always what callers
want when adding up a list that may legitimately be empty.
Examples#
my $n = sum0 1..10; # 55
my $n = sum0 (); # 0
my $n = sum0 grep { $_ > 0 } @x; # total of positives, 0 if none
Differences from upstream#
Fully compatible with upstream.
See also#
sum— the original; returnsundefon empty input.product— identity element for multiplication (returns1on empty).