Skip to content

Commit

Permalink
Fix last(empty)
Browse files Browse the repository at this point in the history
It's actually empty now. (Makes last/1 even slower than before, though.)
  • Loading branch information
muhmuhten committed Mar 22, 2019
1 parent cb0ee84 commit 0daa5a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def all(condition): all(.[]; condition);
def any(condition): any(.[]; condition);
def all: all(.[]; .);
def any: any(.[]; .);
def last(g): reduce . as $_ (.; g);
def last(g): reduce . as $_ (.; g|[.]) | .[]?;
def nth($n; g): if $n < 0 then error("nth doesn't support negative indices") else last(limit($n + 1; g)) end;
def first: .[0];
def last: .[-1];
Expand Down
8 changes: 8 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ first(1,error("foo"))
null
1

[first(empty)]
null
[]

[last(empty)]
null
[]

#
# Check that various builtins evalute all arguments where appropriate,
# doing cartesian products where appropriate.
Expand Down

0 comments on commit 0daa5a7

Please sign in to comment.