Skip to content

Commit 45b4acd

Browse files
salonijuneja21sparkprime
authored andcommitted
Implement std.xor for 2 booleans
1 parent 27e6e02 commit 45b4acd

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,19 @@ local html = import 'html.libsonnet';
14341434
},
14351435
],
14361436
},
1437+
{
1438+
name: 'Booleans',
1439+
id: 'booleans',
1440+
fields: [
1441+
{
1442+
name: 'xor',
1443+
params: ['x', 'y'],
1444+
description: |||
1445+
Returns the xor of the two given booleans.
1446+
|||,
1447+
},
1448+
],
1449+
},
14371450
{
14381451
name: 'JSON Merge Patch',
14391452
id: 'json_merge_patch',

stdlib/std.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,4 +1682,6 @@ limitations under the License.
16821682
__array_greater_or_equal(arr1, arr2):: std.__compare_array(arr1, arr2) >= 0,
16831683

16841684
sum(arr):: std.foldl(function(a,b)a+b,arr,0),
1685+
1686+
xor(x, y):: x!=y,
16851687
}

test_suite/stdlib.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,4 +1532,7 @@ std.assertEqual(std.all([]), true) &&
15321532

15331533
std.assertEqual(std.sum([1, 2, 3]), 6) &&
15341534

1535+
std.assertEqual(std.xor(true, false), true) &&
1536+
std.assertEqual(std.xor(true, true), false) &&
1537+
15351538
true

0 commit comments

Comments
 (0)