[
https://issues.apache.org/jira/browse/GROOVY-10032?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-10032:
-------------------------------
Description:
Now that we have this:
{quote}
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]}}
{quote}
It might make sense to re-assess containsWithinBounds behavior:
{code}
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)
{code}
Gives:
{noformat}
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
{noformat}
The IntRange values look good to me.
was:
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]}}
> CLONE - left-open and full-open ranges (consider adjusting
> containsWithinBounds behavior)
> -----------------------------------------------------------------------------------------
>
> Key: GROOVY-10032
> URL: https://issues.apache.org/jira/browse/GROOVY-10032
> Project: Groovy
> Issue Type: New Feature
> Reporter: Björn Kautler
> Assignee: Paul King
> Priority: Major
> Fix For: 4.0.0-alpha-3
>
>
> Now that we have this:
> {quote}
> 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]}}
> {quote}
> It might make sense to re-assess containsWithinBounds behavior:
> {code}
> 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)
> {code}
> Gives:
> {noformat}
> 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
> {noformat}
> The IntRange values look good to me.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)