diff options
author | pkoppstein <pkoppstein@gmail.com> | 2023-07-24 20:12:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 09:12:23 +0900 |
commit | 8f49600a6b717ada5973d518a9f042a4f2f8c58b (patch) | |
tree | afb359d9b53b3df3fb5b31f50ae707a17841a0c8 /src | |
parent | 330559643a67fd5f0818a29d5729db97e138390d (diff) |
builtin.jq: simpler and faster transpose (#2758)
Diffstat (limited to 'src')
-rw-r--r-- | src/builtin.jq | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/builtin.jq b/src/builtin.jq index a13d7845..45ba3060 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -181,14 +181,7 @@ def combinations(n): | combinations; # transpose a possibly jagged matrix, quickly; # rows are padded with nulls so the result is always rectangular. -def transpose: - if . == [] then [] - else . as $in - | (map(length) | max) as $max - | length as $length - | reduce range(0; $max) as $j - ([]; . + [reduce range(0;$length) as $i ([]; . + [ $in[$i][$j] ] )] ) - end; +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): |