Sum

Sum( arrayOrSet )
Sum( arrayOrSet )
Sum( arrayOrSet )
Sum( arrayOrSet )
sum( arrayOrSet )
Sum( arrayOrSet )

Description

The Sum function returns the sum of all items in arrayOrSet, which is an Array, Page, or Set.

Parameters

Argument Type Definition and Requirements

arrayOrSet

Array, Page, or Set

The array, page, or set that should have its items summed.

Returns

A Number representing the sum of all items in arrayOrSet.

Examples

The following query returns the sum of items in the provided array:

Value result = await client.Query(
  Sum(Arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
);

IResult<Value> data = result.To<Value>();
data.Match(
  Success: value => Console.WriteLine($"{value}"),
  Failure: error => Console.WriteLine($"Query failed:\n{error}")
);
result, err := client.Query(
  f.Sum(f.Arr{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
System.out.println(
    client.query(
        Sum(
            Arr(
                Value(1), Value(2), Value(3), Value(4), Value(5),
                Value(6), Value(7), Value(8), Value(9), Value(10)
            )
        )
    ).get()
);
client.query(
  q.Sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
)
.then((ret) => console.log(ret))
println(Await.result(
  client.query(
    Sum(Arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
  ),
  5.seconds)
)
print(client.query(
  q.sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
))
LongV(55)
55
55
55
55
55

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!