Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant subexpression in Generators and iterators example in doc #3222

Open
jhcarl0814 opened this issue Dec 14, 2024 · 0 comments
Open

Redundant subexpression in Generators and iterators example in doc #3222

jhcarl0814 opened this issue Dec 14, 2024 · 0 comments

Comments

@jhcarl0814
Copy link

Describe the bug
jq 1.7 Manual / Generators and iterators

To Reproduce
In the first example:
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)'

  1. Redundant operation: else . produces an extra value beyond upto, then | select((by > 0 and . < upto) or (by < 0 and . > upto)) filters it.
  2. Should result in empty when init == upto.

Expected behavior
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)'

Environment (please complete the following information):
/

Additional context
/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant