Merge pull request #1837 from muhmuhten/limit_0

This commit is contained in:
Nico Williams authored and GitHub committed 2019-02-21 08:17:41 -06:00
commit 9a0d5be790
2 files changed
+11 -3

No files matched your search

+3 -3
View File
@@ -168,9 +168,9 @@ def until(cond; next):
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; .-1; $item, if . <= 0 then break $out else empty end)
end;
if $n > 0 then label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
elif $n == 0 then empty
else exp 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);
+8
View File
@@ -304,6 +304,14 @@ null
[11,22,33,44,55,66,77,88,99]
[11,22,33]
[limit(0; error)]
"badness"
[]
[limit(1; 1, error)]
"badness"
[1]
[first(range(.)), last(range(.)), nth(0; range(.)), nth(5; range(.)), try nth(-1; range(.)) catch .]
10
[0,9,0,5,"nth doesn't support negative indices"]