Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johnbartholomew opened this issue Mar 21, 2025 · 0 comments
Open

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

johnbartholomew opened this issue Mar 21, 2025 · 0 comments

Comments

@johnbartholomew
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant