baml.Summable

Summation for numeric arrays.

Reference version

Signature

interface baml.Summable

Summation for numeric arrays.

Implemented for int[], summing to int, and float[], summing to float. Sum is the element's own numeric type, so xs.sum() stays in the array's number domain with no implicit widening: int and float are distinct types, and there is deliberately no int[] -> float sum. To sum integer data as floats, map first — ints.map((x: int) -> float { x * 1.0 }).sum().

Source:<builtin>/baml/containers.bamlbytes 33442–33968

Associated types

type Sum

Required instance methods

function

sum

(self) -> (Self as baml.Summable).Sum throws never

Adds every element left to right, starting from the additive identity, so an empty collection sums to that identity.

throws never does not make summation total: an implementation over a bounded integer type overflows the same way repeated + does, and overflow is a panic rather than an error. See each implementation for its range behaviour.