jsonnet
jsonnet copied to clipboard
std.flatMap behaviour is strange if f returns a string
The docs say:
Apply the given function to every element of
arrto form a new array then flatten the result. The argumentarrmust be an array or a string. Ifarris an array, functionfuncmust return an array. Ifarris a string, functionfuncmust return an string.
However, this is not enforced in all combinations. Example:
# Array input, function returns array, behaves as expected:
$ ./jsonnet -e 'std.flatMap(function(x) [x], ["a", "b", "c"])'
[
"a",
"b",
"c"
]
# Array input, function returns a string, behaves strangely:
$ ./jsonnet -e 'std.flatMap(function(x) x, ["a", "b", "c"])'
"[ ]abc"
Noticed while testing https://github.com/google/go-jsonnet/pull/797