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

Fix redundant subexpression in Generators and iterators example in doc #3239

Conversation

jhcarl0814
Copy link
Contributor

@jhcarl0814 jhcarl0814 commented Jan 26, 2025

Fixes #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)'

@jhcarl0814 jhcarl0814 force-pushed the fix_redundant_subexpression_in_generators_and_iterators_example_in_doc branch 5 times, most recently from a33a1b3 to 252b16b Compare January 26, 2025 23:56
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)'`
@jhcarl0814 jhcarl0814 force-pushed the fix_redundant_subexpression_in_generators_and_iterators_example_in_doc branch from 252b16b to 3f82b37 Compare January 26, 2025 23:59
@itchyny itchyny added the docs label Jan 27, 2025
Copy link
Contributor

@itchyny itchyny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@itchyny itchyny merged commit da28628 into jqlang:master Jan 27, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redundant subexpression in Generators and iterators example in doc
2 participants