diff options
author | Nicolas Williams <nico@cryptonector.com> | 2018-03-06 11:28:38 -0600 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2018-03-06 11:29:13 -0600 |
commit | e113c67d5116e52e536fae8f2d52516bd2cefa31 (patch) | |
tree | b3407018b90fa852d8dbb19a1914c8142641f382 | |
parent | bf88c73c20ff1642aa2566ae67df18ca5b4b63ab (diff) |
limit/2 evals exp one time too many
-rw-r--r-- | src/builtin.jq | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/builtin.jq b/src/builtin.jq index b0e8775a..c445f1a2 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -167,7 +167,14 @@ def until(cond; next): def _until: if cond then . else (next|_until) end; _until; -def limit($n; exp): if $n < 0 then exp else label $out | foreach exp as $item ([$n, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1]) end; +def limit($n; exp): + if $n < 0 then exp else + label $out | + foreach exp as $item ( + [$n, null]; + if .[0] < 1 then break $out + else [.[0] -1, $item] end; + if .[0] == 0 then .[1], break $out else .[1] end) end; def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0); def first(g): label $out | g | ., break $out; def last(g): reduce g as $item (null; $item); |