summaryrefslogtreecommitdiffstats
path: root/src/builtin.jq
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtin.jq')
-rw-r--r--src/builtin.jq4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/builtin.jq b/src/builtin.jq
index aac22cb7..146a64a3 100644
--- a/src/builtin.jq
+++ b/src/builtin.jq
@@ -163,7 +163,9 @@ def any(condition): any(.[]; condition);
def all: all(.[]; .);
def any: any(.[]; .);
def last(g): reduce g as $item (null; $item);
-def nth($n; g): if $n < 0 then error("nth doesn't support negative indices") else last(limit($n + 1; g)) end;
+def nth($n; g):
+ if $n < 0 then error("nth doesn't support negative indices")
+ else label $out | foreach g as $item ($n + 1; . - 1; if . <= 0 then $item, break $out else empty end) end;
def first: .[0];
def last: .[-1];
def nth($n): .[$n];