diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index 38b8c5bfbe..3abd4892b6 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -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'] diff --git a/jq.1.prebuilt b/jq.1.prebuilt index fadad46cc5..50de569a86 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -3644,7 +3644,7 @@ All jq functions can be generators just by using builtin generators\. It is also . .nf -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)\' +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)\' null => 0, 3, 6, 9 diff --git a/tests/man.test b/tests/man.test index 5489c5e20e..12957c8fc4 100644 --- a/tests/man.test +++ b/tests/man.test @@ -927,7 +927,7 @@ foreach .[] as $item (0; . + 1; {index: ., $item}) {"index":2,"item":"bar"} {"index":3,"item":"baz"} -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) +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) null 0 3