Documentation for routine sum

Documentation for routine sum, assembled from the following types:

class List

From List

(List) routine sum

Defined as:

sub    sum($list   --> Numeric:D)
method sum(List:D: --> Numeric:D)

Returns the sum of all elements in the list or 0 if the list is empty. Throws an exception if an element can not be coerced into Numeric.

say (13pi).sum;       # OUTPUT: «7.14159265358979␤» 
say (1"0xff").sum;      # OUTPUT: «256␤» 
say sum(0b11115);       # OUTPUT: «20␤» 

class Range

From Range

(Range) method sum

multi method sum(--> Numeric:D)

Returns the sum of all elements in the Range. Throws X::Str::Numeric if an element can not be coerced into Numeric.

(1..10).sum                                       # 55