I need to evaluate a string with nested function calls. Is there an easy way to do this with groovy?
Edit: Code made more realistic. The context is nonacademic; my function needs to combine and evaluate a bunch of arbitrary strings and values from json files.
JSON file 1 will have strings like:
"biggerThan(isList,0)"
"smallerThan(isList,3)"
"biggerThan(isList,1)"
JSON file 2 will have values like
[4,1]
[1,2,1]
[1,5,6,2,98]
[]
def biggerThan= {func, val->
{v->return func(v) && (v.size() > val)}
}
def isList ={n->
return n instanceof List
}
def a=biggerThan(isList,1)
a([4,1])
// -> returns true in groovy console because [4,1] is a list with size>1