Skip to content

Instantly share code, notes, and snippets.

@charles-dyfis-net
Created July 19, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles-dyfis-net/3f596d0aa19f187b80e6ee167dfc55c3 to your computer and use it in GitHub Desktop.
Save charles-dyfis-net/3f596d0aa19f187b80e6ee167dfc55c3 to your computer and use it in GitHub Desktop.
[1,2,3]
[4,5,6]
[7,8,9]
[]
#!/opt/local/bin/jq -n -f
def nwise(stream; $n):
foreach (stream, nan) as $x ([];
if length == $n then [$x] else . + [$x] end;
if .[-1] | isnan then .[:-1] ## original
#if .[-1] | isnan then if (. | length) > 1 then .[:-1] else empty end ## proposed
elif length == $n then .
else empty
end);
nwise(inputs; 3)
# note that not all operating systems allow a shebang line to contain more than two words
printf '%s\n' {1..9} | /usr/bin/time -l ./partition.jq -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment