Groovy function signatures

3.42K viewsScripting

Hi, just wanted to definitively confirm one way or the other:

I believe for a groovy function to be picked up by Quantrix, its parameters and return types have to be marked specifically as one of String or double (or int, Date etc.). Am I correct in saying we can’t yet define a polymorphic function in groovy that will work as Quantrix function? I.e. I would like a function to take an Object as input and return an Object (which would typically be either a String or a double).

Also I don’t think that varargs work for groovy functions? I.e. a function that accepts a variable number of input arguments.



Great, many thanks Ben. Another feature request for your database then!


Hi Apollo,

It’s true that functions cannot currently take or return instances of [font=””Courier New””]Object[/font]. You [i:3mgpv4h4]can[/i:3mgpv4h4] write a varargs function, but when invoking it from within a formula you have to wrap the argument list using the Quantrix [font=””Courier New””]list[/font] function. Here is an example:

public double mySum(double... args)
double result = 0;
args.collect{result += it}
return result

Use in a formula, no arguments:
A1:B1 = mySum(list())

Use in a formula, with arguments:
A1:B1 = mySum(list(2, 1, 6))

Hope this helps.

Latest Questions