Skip to content
Myr

limit/2 evals exp one time too many

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nicolas Williams · parent bf88c73 · Browse files · 1 file+8 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−1 removed

  • other:+8 added−1 removed

1 file+8 added−1 removed

modified:src/builtin.jq+8 added-1 removed
165 unmodified lines
166def until(cond; next):167 def _until:168 if cond then . else (next|_until) end;169 _until;170def 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;170def limit($n; exp):171 if $n < 0 then exp else172 label $out |173 foreach exp as $item (174 [$n, null];175 if .[0] < 1 then break $out176 else [.[0] -1, $item] end;177 if .[0] == 0 then .[1], break $out else .[1] end) end;178def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0);179def first(g): label $out | g | ., break $out;180def last(g): reduce g as $item (null; $item);181def nth($n; g): if $n < 0 then error("nth doesn't support negative indices") else last(limit($n + 1; g)) end;
134 unmodified lines