groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: Methods for Creating Ranges
Date Wed, 20 Apr 2016 05:15:40 GMT
Hi,

You can just replace the bounds with variables.

def a = 1
def b = 10
def r = a..b

Isn't that what you're looking for?

Guillaume


Le mercredi 20 avril 2016, Gerald Wiltse <jerrywiltse@gmail.com> a écrit :

> I can find no examples of different ways to create a range.  There's a
> plethora of examples on what you can do when you start by creating a range
> like so:  "1..10"
>
> But, how does one create a range when the min and max values are stored in
> variables?  There's no range constructor.  I see that it's a form of a
> list, but I see no helper methods for dynamically creating ranges given a
> min and max value.
>
> I even tried to get really fancy, but this evaluates to a string.
>
> def v = "10..15"
> assert Eval.x(v, "return x")​.getClass()​.name ==
> "​​​​​​​​​​​java.lang.String"​
>
> My use case is this.  I populate a bunch of form fields with variable
> definitions... but they all get passed to my code as strings. But I want to
> pass port ranges and lists and maps. So, the Eval() method is exactly what
> I needed.. it just isn't working for ranges.
>
> Regards,
> Jerry
>
>
> Gerald R. Wiltse
> jerrywiltse@gmail.com
> <javascript:_e(%7B%7D,'cvml','jerrywiltse@gmail.com');>
>
>

-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Product Ninja & Advocate at Restlet <http://restlet.com>

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>

Mime
View raw message