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.

Further tweaks, e.g. i.f.o. explicitness: `map_values(f)` outputs an array if given an array, or an object if given an object.

authored by pkoppstein · committed by Nico Williams · parent 39cf2fb · Browse files · 1 file+18 added−12 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+18 added−12 removed

  • other:+18 added−12 removed

1 file+18 added−12 removed

modified:docs/content/manual/manual.yml+18 added-12 removed
909 unmodified lines
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.914 whereas `map_values(f)` outputs an array if given an array,915 or an object if given an object.916917 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)`.917 When the input to `map_values(f)` is an object, the output918 object has the same keys as the input object except for919 those keys whose values when piped to `f` produce no values920 at all.921922 The key difference between `map(f)` and `map_values(f)` is923 that the former simply forms an array from all the values of924 `($x|f)` for each value, $x, in the input array or object,925 but `map_values(f)` only uses `first($x|f)`.926927 Specifically, for object inputs, `map_value(f)` constructs922 the output object by examining in turn the values of928 the output object by examining in turn the value of929 `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.930 expression produces no values, then the corresponding key931 will be dropped; otherwise, the output object will have that932 value at the key, $k.933928 Here are some examples to clarify the behavior of the two929 filters when applied to arrays. These examples assume the934 Here are some examples to clarify the behavior of `map` and935 `map_values` when applied to arrays. These examples assume the936 input is `[1]` in all cases:937932 map(.+1) #=> [2]938 map(.+1) #=> [2]939 map(., .) #=> [1,1]940 map(empty) #=> []941942 map_values(.+1) #=> [2]
2556 unmodified lines