add skip/2 as the counterpart to limit/2 (#3181)
I also changed the behavior of limit/2 with negative count to emit an error, like nth/2 does. Also, I redefined nth/2 using skip/2 to minimize the impact of growth of builtin filters.
This commit is contained in:
1 parent
860af44fee
commit
1bebd23aad
5 files changed
+70
-13
No files matched your search
Generated
+19
-4
@@ -1,5 +1,5 @@
|
||||
.
|
||||
.TH "JQ" "1" "August 2024" "" ""
|
||||
.TH "JQ" "1" "September 2024" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBjq\fR \- Command\-line JSON processor
|
||||
@@ -3435,14 +3435,14 @@ jq \'isempty(\.[])\'
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "limit(n; exp)"
|
||||
The \fBlimit\fR function extracts up to \fBn\fR outputs from \fBexp\fR\.
|
||||
.SS "limit(n; expr)"
|
||||
The \fBlimit\fR function extracts up to \fBn\fR outputs from \fBexpr\fR\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
jq \'[limit(3;\.[])]\'
|
||||
jq \'[limit(3; \.[])]\'
|
||||
[0,1,2,3,4,5,6,7,8,9]
|
||||
=> [0,1,2]
|
||||
.
|
||||
@@ -3450,6 +3450,21 @@ jq \'[limit(3;\.[])]\'
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "skip(n; expr)"
|
||||
The \fBskip\fR function skips the first \fBn\fR outputs from \fBexpr\fR\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
jq \'[skip(3; \.[])]\'
|
||||
[0,1,2,3,4,5,6,7,8,9]
|
||||
=> [3,4,5,6,7,8,9]
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.SS "first(expr), last(expr), nth(n; expr)"
|
||||
The \fBfirst(expr)\fR and \fBlast(expr)\fR functions extract the first and last values from \fBexpr\fR, respectively\.
|
||||
.
|
||||
|
||||
Reference in new issue
Block a user