Skip to content
Myr

manual.yml: further tweaks re map and map_values

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

A more systematic exposition

authored by pkoppstein · committed by Nico Williams · parent d710324 · Browse files · 1 file+34 added−11 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+34 added−11 removed

  • other:+34 added−11 removed

1 file+34 added−11 removed

modified:docs/content/manual/manual.yml+34 added-11 removed
904 unmodified lines
905906 - title: "`map(f)`, `map_values(f)`"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. For example, `map(.+1)` will increment each element912 of an array of numbers, and `map(.,.)` will duplicate each913 element of the input array.909 For any filter `f`, `map(f)` and `map_values(f)` apply `f`910 to each of the values in the input array or object, that is,911 to the values of `.[]`.912 913 In the absence of errors, `map(f)` always outputs an array914 whereas `map_values(f)` outputs an array or an object915 depending on the type of the input.916915 `map(f)` is equivalent to `[.[] | f]`. In fact, this is how it's defined.917 One important difference is that whereas `map(f)` simply918 forms an array from all the values of `($x|f)` for each value,919 $x, of the input, `map_values(f)` only uses `first($x|f)`.920917 `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.921 Specifically, for object inputs, `map_value(f)` constructs922 the output object by examining in turn the values of923 `first(.[$k]|f)` for each key, $k, of the input. If this924 expression produces no values (i.e., is equivalent to925 `empty`), the corresponding key will be dropped; otherwise,926 the output object will have this value at the key, $k.927928 Here are some examples to clarify the behavior of the two929 filters when applied to arrays. These examples assume the930 input is `[1]` in all cases:931932 map(.+1) #=> [2]933 map(., .) #=> [1,1]934 map(empty) #=> []935936 map_values(.+1) #=> [2]937 map_values(., .) #=> [1]938 map_values(empty) #=> []939940 `map(f)` is equivalent to `[.[] | f]` and941 `map_values(f)` is equivalent to `.[] |= f`.942 943 In fact, these are their implementations.944945946 examples:947 - program: 'map(.+1)'948 input: '[1,2,3]'949 output: ['[2,3,4]']
2543 unmodified lines