-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
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)'
- Redundant operation:
else .
produces an extra value beyondupto
, then| select((by > 0 and . < upto) or (by < 0 and . > upto))
filters it. - Should result in
empty
wheninit == 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
/