Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0-alpha-3
-
None
Description
Now that we have this:
I found there are right-open ranges like 1..<5 for [1, 2, 3, 4], but no left-open ranges and full-open ranges.
I'd like to suggest adding those, e. g. 1<..5 for [2, 3, 4, 5] and 1<..<5 for [2, 3, 4].
For decimals it would be similar, just omitting the lower bound if it matches.
Currently
3.5..<5.7 gives [3.5, 4.5, 5.5]
3.5..<5.5 gives [3.5, 4.5]So with my suggestion it would then probably be
3.5<..5.5 gives [4.5, 5.5]
3.5<..<5.7 gives [4.5, 5.5]
3.5<..<5.5 gives [4.5]
It might make sense to re-assess containsWithinBounds behavior:
def u = 3.5..5.5 println u println u.toList() println u.containsWithinBounds(3.5) println u.containsWithinBounds(4.5) println u.containsWithinBounds(5.5) def v = 3.5..<5.5 println v println v.toList() println v.containsWithinBounds(3.5) println v.containsWithinBounds(4.5) println v.containsWithinBounds(5.5) def w = 3.5<..5.5 println w println w.toList() println w.containsWithinBounds(3.5) println w.containsWithinBounds(4.5) println w.containsWithinBounds(5.5) def x = 3.5<..<5.5 println x println x.toList() println x.containsWithinBounds(3.5) println x.containsWithinBounds(4.5) println x.containsWithinBounds(5.5) def ui = 3..5 println ui println ui.toList() println ui.containsWithinBounds(3) println ui.containsWithinBounds(4) println ui.containsWithinBounds(5) def vi = 3..<5 println vi println vi.toList() println vi.containsWithinBounds(3) println vi.containsWithinBounds(4) println vi.containsWithinBounds(5) def wi = 3<..5 println wi println wi.toList() println wi.containsWithinBounds(3) println wi.containsWithinBounds(4) println wi.containsWithinBounds(5) def xi = 3<..<5 println xi println xi.toList() println xi.containsWithinBounds(3) println xi.containsWithinBounds(4) println xi.containsWithinBounds(5)
Gives:
3.5..5.5 [3.5, 4.5, 5.5] true true true 3.5..<5.5 [3.5, 4.5] true true true 3.5<..5.5 [4.5, 5.5] true true true 3.5<..<5.5 [4.5] true true true 3..5 [3, 4, 5] true true true 3..<5 [3, 4] true true false 3<..5 [4, 5] false true true 3<..<5 [4] false true false
The IntRange values look good to me.
Attachments
Issue Links
- is a clone of
-
GROOVY-9649 left-open and full-open ranges
- Closed