sum0#
Add up every value in the list, returning 0 for an empty list.
תקציר#
my $total = sum0 @values;
my $total = sum0 (); # 0, not undef
מה מוחזר#
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.
דוגמאות#
my $n = sum0 1..10; # 55
my $n = sum0 (); # 0
my $n = sum0 grep { $_ > 0 } @x; # total of positives, 0 if none
הבדלים מן ה-upstream#
Fully compatible with upstream.
ראו גם#
sum- the original; returnsundefon empty input.product- identity element for multiplication (returns1on empty).