Merge pull request #1837 from muhmuhten/limit_0
This commit is contained in:
2 files changed
+11
-3
No files matched your search
+3
-3
@@ -168,9 +168,9 @@ def until(cond; next):
|
|||||||
if cond then . else (next|_until) end;
|
if cond then . else (next|_until) end;
|
||||||
_until;
|
_until;
|
||||||
def limit($n; exp):
|
def limit($n; exp):
|
||||||
if $n < 0 then exp
|
if $n > 0 then label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
|
||||||
else label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
|
elif $n == 0 then empty
|
||||||
end;
|
else exp end;
|
||||||
def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0);
|
def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0);
|
||||||
def first(g): label $out | g | ., break $out;
|
def first(g): label $out | g | ., break $out;
|
||||||
def last(g): reduce g as $item (null; $item);
|
def last(g): reduce g as $item (null; $item);
|
||||||
|
|||||||
@@ -304,6 +304,14 @@ null
|
|||||||
[11,22,33,44,55,66,77,88,99]
|
[11,22,33,44,55,66,77,88,99]
|
||||||
[11,22,33]
|
[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 .]
|
[first(range(.)), last(range(.)), nth(0; range(.)), nth(5; range(.)), try nth(-1; range(.)) catch .]
|
||||||
10
|
10
|
||||||
[0,9,0,5,"nth doesn't support negative indices"]
|
[0,9,0,5,"nth doesn't support negative indices"]
|
||||||
|
|||||||
Reference in new issue
Block a user