Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/_stdlib_gen/stdlib-content.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,20 @@ local html = import 'html.libsonnet';
},
],
},
{
name: 'flattenDeepArray',
params: ['value'],
availableSince: 'upcoming',
description: |||
Concatenate an array containing values and arrays into a single flattened array.
|||,
examples: [
{
input: 'std.flattenDeepArray([[1, 2], [], [3, [4]], [[5, 6, [null]], [7, 8]]])',
output: std.flattenDeepArray([[1, 2], [], [3, [4]], [[5, 6, [null]], [7, 8]]]),
},
],
Comment thread
bitmaybewise marked this conversation as resolved.
},
{
name: 'reverse',
params: ['arrs'],
Expand Down
6 changes: 6 additions & 0 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,12 @@ limitations under the License.
flattenArrays(arrs)::
std.foldl(function(a, b) a + b, arrs, []),

flattenDeepArray(value)::
if std.isArray(value) then
[y for x in value for y in std.flattenDeepArray(x)]
else
[value],

manifestIni(ini)::
local body_lines(body) =
std.join([], [
Expand Down
5 changes: 5 additions & 0 deletions test_suite/stdlib.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ std.assertEqual(std.lines(['a', null, 'b']), 'a\nb\n') &&

std.assertEqual(std.flattenArrays([[1, 2, 3], [4, 5, 6], []]), [1, 2, 3, 4, 5, 6]) &&

std.assertEqual(std.flattenDeepArray([]), []) &&
std.assertEqual(std.flattenDeepArray([1, 2, 3]), [1, 2, 3]) &&
std.assertEqual(std.flattenDeepArray([1, [2, 3]]), [1, 2, 3]) &&
std.assertEqual(std.flattenDeepArray([[1], [2, 3], [[null]]]), [1, 2, 3, null]) &&

std.assertEqual(
std.manifestIni({
main: { a: '1', b: '2' },
Expand Down