limit/2 evals exp one time too many

This commit is contained in:
Nicolas Williams committed 2018-03-06 11:29:13 -06:00
1 parent bf88c73c20
commit e113c67d51
1 file changed
+8 -1
+8 -1
View File
@@ -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);