Skip to content

Commit

Permalink
Fix redundant subexpression in Generators and iterators example in doc
Browse files Browse the repository at this point in the history
jqlang#3222
`jq 'def range(init; upto; by): def _range: if (by > 0 and . < upto) or (by < 0 and . > upto) then ., ((.+by)|_range) else . end; if by == 0 then init else init|_range end | select((by > 0 and . < upto) or (by < 0 and . > upto)); range(0; 10; 3)'`
Can be simplified and corrected to:
`jq 'def range(init; upto; by): def _range: if (by > 0 and . < upto) or (by < 0 and . > upto) then ., ((.+by)|_range) else empty end; if init == upto then empty elif by == 0 then init else init|_range end; range(0; 10; 3)'`
  • Loading branch information
jhcarl0814 committed Jan 26, 2025
1 parent 31dac28 commit 3f82b37
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions docs/content/manual/dev/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3223,9 +3223,8 @@ sections:
def _range:
if (by > 0 and . < upto) or (by < 0 and . > upto)
then ., ((.+by)|_range)
else . end;
if by == 0 then init else init|_range end |
select((by > 0 and . < upto) or (by < 0 and . > upto));
else empty end;
if init == upto then empty elif by == 0 then init else init|_range end;
range(0; 10; 3)'
input: 'null'
output: ['0', '3', '6', '9']
Expand Down
2 changes: 1 addition & 1 deletion jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/man.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f82b37

Please sign in to comment.