Skip to content
Myr

manual.yml: clarify explanation of map_values, including description of new behavior

Before adoption: this commit came in with the history the project adopted, so no landing records it.

#2466

authored by pkoppstein · committed by Nico Williams · parent ce3701f · Browse files · 1 file+19 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−6 removed

  • other:+19 added−6 removed

1 file+19 added−6 removed

modified:docs/content/manual/manual.yml+19 added-6 removed
906 unmodified lines
907 body: |908909 For any filter `f`, `map(f)` will run that filter for each910 element of the input array, and return the outputs in a new911 array. `map(.+1)` will increment each element of an array of numbers.911 array. For example, `map(.+1)` will increment each element912 of an array of numbers, and `map(.,.)` will duplicate each913 element of the input array.914913 Similarly, `map_values(f)` will run that filter for each element,914 but it will return an object when an object is passed.915 `map(f)` is equivalent to `[.[] | f]`. In fact, this is how it's defined.916916 `map(f)` is equivalent to `[.[] | f]`. In fact, this is how917 it's defined. Similarly, `map_values(f)` is defined as `.[] |= f`.918917 `map_values(f)` is similarly defined as `.[] |= f`. This918 essentially means that each value, $v, in the input array or919 object is replaced by `first($v|f)`, it being understood920 that if the input is an object, then keys for which this921 expression is empty will be removed.922 923 examples:924 - program: 'map(.+1)'925 input: '[1,2,3]'926 output: ['[2,3,4]']
1 unmodified line
928 - program: 'map_values(.+1)'929 input: '{"a": 1, "b": 2, "c": 3}'930 output: ['{"a": 2, "b": 3, "c": 4}']931932 - program: 'map(., .)'933 input: '[1,2]'934 output: ['[1,1,2,2]']935936 - program: 'map_values(. // empty)'937 input: '{"a": null, "b": true, "c": false}'938 output: ['{"b":true}']939940941 - title: "`pick(pathexps)`"942 body: |943 944 Emit the projection of the input object or array defined by the specified
2525 unmodified lines