array and object destructuring (fix #533)

`. as [$i, $j, $k] | ...`
`. as {a: $i, b: $j} | ...`
`. as [[[$i]], {a: $j}] | ...`
`foreach . as [$i, $j, $k] (...)`
`reduce . as {a: $i, b: $j} (...)`
This commit is contained in:
David Tolnay authored and Nicolas Williams committed 2015-06-09 17:29:48 -05:00
1 parent 2e96fb2c9b
commit d3343d5113
6 files changed
+1148 -869

No files matched your search

+8
View File
@@ -2147,6 +2147,11 @@ sections:
with `$x` set to that value. Thus `as` functions as something of a
foreach loop.
Multiple variables may be declared using a single `as` expression by
providing a pattern that matches the structure of the input:
. as {realnames: $names, posts: [$first, $second]} | ...
Variables are scoped over the rest of the expression that defines
them, so
@@ -2171,6 +2176,9 @@ sections:
- program: '. as $i|[(.*2|. as $i| $i), $i]'
input: '5'
output: ['[10,5]']
- program: '. as [$a, $b, {c: $c}] | $a + $b + $c'
input: '[2, 3, {c: 4, d: 5}]'
output: ['9']
- title: 'Defining Functions'
body: |