Skip to content

Commit 8d6af65

Browse files
rohitjangidsparkprime
authored andcommitted
Add std.sum in standard library
1 parent ffa5461 commit 8d6af65

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,16 @@ local html = import 'html.libsonnet';
13081308
|||,
13091309
]),
13101310
},
1311+
{
1312+
name: 'sum',
1313+
params: ['arr'],
1314+
availableSince: 'v0.19.2',
1315+
description: html.paragraphs([
1316+
|||
1317+
Return sum of all element in <code>arr</code>.
1318+
|||,
1319+
]),
1320+
},
13111321
],
13121322
},
13131323
{

stdlib/std.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,4 +1681,5 @@ limitations under the License.
16811681
__array_less_or_equal(arr1, arr2):: std.__compare_array(arr1, arr2) <= 0,
16821682
__array_greater_or_equal(arr1, arr2):: std.__compare_array(arr1, arr2) >= 0,
16831683

1684+
sum(arr):: std.foldl(function(a,b)a+b,arr,0),
16841685
}

test_suite/stdlib.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,4 +1530,6 @@ std.assertEqual(std.all([true, false]), false) &&
15301530
std.assertEqual(std.all([true, true]), true) &&
15311531
std.assertEqual(std.all([]), true) &&
15321532

1533+
std.assertEqual(std.sum([1, 2, 3]), 6) &&
1534+
15331535
true

0 commit comments

Comments
 (0)