Skip to content

Commit e3a330f

Browse files
rohitjangidsparkprime
authored andcommitted
feat: implement std.contains
1 parent e6bf0ee commit e3a330f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

+10
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,16 @@ local html = import 'html.libsonnet';
14211421
|||,
14221422
]),
14231423
},
1424+
{
1425+
name: 'contains',
1426+
params: ['arr', 'elem'],
1427+
availableSince: 'upcoming',
1428+
description: html.paragraphs([
1429+
|||
1430+
Return true if given <code>elem</code> is present in <code>arr</code>, false otherwise.
1431+
|||,
1432+
]),
1433+
},
14241434
],
14251435
},
14261436
{

stdlib/std.jsonnet

+2
Original file line numberDiff line numberDiff line change
@@ -1710,4 +1710,6 @@ limitations under the License.
17101710
round(x):: std.floor(x + 0.5),
17111711

17121712
isEmpty(str):: std.length(str) == 0,
1713+
1714+
contains(arr, elem):: std.any([e == elem for e in arr]),
17131715
}

test_suite/stdlib.jsonnet

+3
Original file line numberDiff line numberDiff line change
@@ -1556,4 +1556,7 @@ std.assertEqual(std.round(1.5), 2) &&
15561556
std.assertEqual(std.isEmpty(''), true) &&
15571557
std.assertEqual(std.isEmpty('non-empty string'), false) &&
15581558

1559+
std.contains(std.contains([1, 2, 3], 2), true) &&
1560+
std.contains(std.contains([1, 2, 3], "foo"), false) &&
1561+
15591562
true

0 commit comments

Comments
 (0)