walk/1
This commit is contained in:
1 parent
c426d494f0
commit
16d0e528aa
2 files changed
+38
No files matched your search
@@ -1522,6 +1522,33 @@ sections:
|
||||
- 4
|
||||
- 16
|
||||
|
||||
- title: "`walk(f)`"
|
||||
body: |
|
||||
|
||||
The `walk(f)` function applies f recursively to every
|
||||
component of the input entity. When an array is
|
||||
encountered, f is first applied to its elements and then to
|
||||
the array itself; when an object is encountered, f is first
|
||||
applied to all the values and then to the object. In
|
||||
practice, f will usually test the type of its input, as
|
||||
illustrated in the following examples. The first example
|
||||
highlights the usefulness of processing the elements of an
|
||||
array of arrays before processing the array itself. The second
|
||||
example shows how all the keys of all the objects within the
|
||||
input can be considered for alteration.
|
||||
|
||||
examples:
|
||||
- program: 'walk(if type == "array" then sort else . end)'
|
||||
input: '[[4, 1, 7], [8, 5, 2], [3, 6, 9]]'
|
||||
output:
|
||||
- '[[1,4,7],[2,5,8],[3,6,9]]'
|
||||
|
||||
- program: 'walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )
|
||||
input: '[ { "_a": { "__b": 2 } } ]'
|
||||
output:
|
||||
- '[{"a":{"b":2}}]'
|
||||
|
||||
|
||||
- title: "`..`"
|
||||
body: |
|
||||
|
||||
|
||||
Reference in new issue
Block a user