Home / Docs / Standard library / Prelude
sum
A function of the prelude, in scope in every module. Edition 0.1 and later.
Edition 0.1
pub sum(xs: List[Int]) -> IntThe exact sum of the elements as an Int, 0 when xs is empty; Int has no bound, so it never overflows. In edition 0.2 and later it takes any integer type and adds the values as Int (spec/14 §1, spec/20 §6).
Edition 0.2 and later
pub sum[T: Integer](xs: List[T]) -> IntThe exact sum of the elements as an Int, 0 when xs is empty; Int has no bound, so it never overflows. In edition 0.2 and later it takes any integer type and adds the values as Int (spec/14 §1, spec/20 §6).
In editions 0.2, 0.3, 0.4, 0.5. In edition 0.1: sum(xs: List[Int]) -> Int: Int elements only.
Parameters
xs: the list
Returns
Int: the exact sum of the elements, as an Int; 0 for an empty list; it never overflows.
See also
Example
module shop
--- The total of a cart, in cents.
pub main() -> Unit
uses @console: Console[print]
=
let total = [1999, 499].sum()
@console.print("total {total}")una run . prints:
total 2498Specification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.