Skip to content

Commit e113c67

Browse files
committed
limit/2 evals exp one time too many
1 parent bf88c73 commit e113c67

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/builtin.jq

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,14 @@ def until(cond; next):
167167
def _until:
168168
if cond then . else (next|_until) end;
169169
_until;
170-
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;
170+
def limit($n; exp):
171+
if $n < 0 then exp else
172+
label $out |
173+
foreach exp as $item (
174+
[$n, null];
175+
if .[0] < 1 then break $out
176+
else [.[0] -1, $item] end;
177+
if .[0] == 0 then .[1], break $out else .[1] end) end;
171178
def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0);
172179
def first(g): label $out | g | ., break $out;
173180
def last(g): reduce g as $item (null; $item);

0 commit comments

Comments
 (0)