Skip to content

Commit

Permalink
builtin.jq: [] | transpose #=> []
Browse files Browse the repository at this point in the history
For backward-compatibility.
Add check in jq.test
  • Loading branch information
pkoppstein committed Jul 24, 2023
1 parent e7b5327 commit 08da3a9
Show file tree
Hide file tree
Showing 2 changed files with 5 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 @@ -182,7 +182,7 @@ def combinations(n):
# transpose a possibly jagged matrix, quickly;
# rows are padded with nulls so the result is always rectangular.
# Using map(length) turns out to be faster than using max(stream)
def transpose: [range(0; map(length)|max) as $i | [.[][$i]]];
def transpose: [range(0; map(length)|max // 0) as $i | [.[][$i]]];
def in(xs): . as $x | xs | has($x);
def inside(xs): . as $x | xs | contains($x);
def repeat(exp):
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,10 @@ transpose
[[1], [2,3]]
[[1,2],[null,3]]

transpose
[]
[]

ascii_upcase
"useful but not for é"
"USEFUL BUT NOT FOR é"
Expand Down

0 comments on commit 08da3a9

Please sign in to comment.