-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Docs: unclear explanation of map_values()
#2466
Comments
Hey, I think you have understood it correctly. If your curious you can check builtin.jq for how it's implemented I suggest you make a PR and I like how you listed the cases. But it might take some time until it gets merged, the people with merge rights works a bit sporadically. |
Hej! Tusentack. Det var inte i går! Thanks. I will keep my expectations quite reasonable. 👍 |
Det samma! hoppas allt är bra :) You can read in #2305 about the status of jq, i really hope something can be sorted out. |
So if you want to map over the values of an object but keep it an object, then you should use |
I think of jq's [ 10, 20, 30 ] |
map(. + (-1, 0, 1))
# [9,10,11,19,20,21,29,30,31] [ 1, 1, 1, 2, 4, 5, 8, 1 ] |
map(if . % 2 == 0 then ., "hi" else . + 1 end)
# [2,2,2,2,"hi",4,"hi",6,8,"hi",2] I almost never use A reason why I prefer using [ range(10) | tostring ] | .[] |= try tonumber catch []
# jq 1.6: [[],[],[],[],[],[],[],[],[],[]]
# expected: [0,1,2,3,4,5,6,7,8,9] [ range(10) | tostring ] | map(try tonumber catch [])
# jq 1.6: [0,1,2,3,4,5,6,7,8,9]
# expected: [0,1,2,3,4,5,6,7,8,9] Note that this bug has been fixed on master |
Me too. And I almost never use |
Fixed by #2680 |
I love jq. Thank you.
I read the section of the Manual on
map()
andmap_values()
, and although I eventually believe I understand it, I found it hard to grasp the meaning of the text and only understood once I saw the example. I would like to propose a change to improve the text, but I don't want to do that until I better understand what you folks had had in mind when you wrote the text.If you'd rather I merely propose a change in a PR, please comment saying so and I'll do it.
This is the text that confused me:
I think this means the following. Please tell me if I have it right or wrong.
x
is not an object, thenmap_values()
behaves exactly likemap()
.x
is an object, thenmap_values()
transforms only the values exactly likemap()
would, but then returns an object with the same keys and the new values.Of course, those explanations are also terrible, but it's the best I can draft at this moment while my brain wants to get back to my current task. :)
Questions:
map_values()
does?The text was updated successfully, but these errors were encountered: