manual.yml: further tweaks re map and map_values
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.
This commit is contained in:
1 parent
39cf2fb7a6
commit
8345a8a62b
1 file changed
+17
-11
@@ -911,22 +911,28 @@ sections:
|
|||||||
to the values of `.[]`.
|
to the values of `.[]`.
|
||||||
|
|
||||||
In the absence of errors, `map(f)` always outputs an array
|
In the absence of errors, `map(f)` always outputs an array
|
||||||
whereas `map_values(f)` outputs an array or an object
|
whereas `map_values(f)` outputs an array if given an array,
|
||||||
depending on the type of the input.
|
or an object if given an object.
|
||||||
|
|
||||||
One important difference is that whereas `map(f)` simply
|
When the input to `map_values(f)` is an object, the output
|
||||||
forms an array from all the values of `($x|f)` for each value,
|
object has the same keys as the input object except for
|
||||||
$x, of the input, `map_values(f)` only uses `first($x|f)`.
|
those keys whose values when piped to `f` produce no values
|
||||||
|
at all.
|
||||||
|
|
||||||
|
The key difference between `map(f)` and `map_values(f)` is
|
||||||
|
that the former simply forms an array from all the values of
|
||||||
|
`($x|f)` for each value, $x, in the input array or object,
|
||||||
|
but `map_values(f)` only uses `first($x|f)`.
|
||||||
|
|
||||||
Specifically, for object inputs, `map_value(f)` constructs
|
Specifically, for object inputs, `map_value(f)` constructs
|
||||||
the output object by examining in turn the values of
|
the output object by examining in turn the value of
|
||||||
`first(.[$k]|f)` for each key, $k, of the input. If this
|
`first(.[$k]|f)` for each key, $k, of the input. If this
|
||||||
expression produces no values (i.e., is equivalent to
|
expression produces no values, then the corresponding key
|
||||||
`empty`), the corresponding key will be dropped; otherwise,
|
will be dropped; otherwise, the output object will have that
|
||||||
the output object will have this value at the key, $k.
|
value at the key, $k.
|
||||||
|
|
||||||
Here are some examples to clarify the behavior of the two
|
Here are some examples to clarify the behavior of `map` and
|
||||||
filters when applied to arrays. These examples assume the
|
`map_values` when applied to arrays. These examples assume the
|
||||||
input is `[1]` in all cases:
|
input is `[1]` in all cases:
|
||||||
|
|
||||||
map(.+1) #=> [2]
|
map(.+1) #=> [2]
|
||||||
|
|||||||
Reference in new issue
Block a user