Skip to content

std.flatMap behaviour is strange if f returns a string #1226

Open
@johnbartholomew

Description

@johnbartholomew

The docs say:

Apply the given function to every element of arr to form a new array then flatten the result. The argument arr must be an array or a string. If arr is an array, function func must return an array. If arr is a string, function func must 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 google/go-jsonnet#797

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions