Reputation: 41
I have been trying to create a function in Foundry that will take n number of parameters and concatenate the strings with a given delimiter.
When using a rest parameter, the input defaults to requiring data type array, not string. It also only accepts one array as an input parameter, not multiple string values:
Example function:
@Function()
public stringAppendFunction(delimiter: string, ...names: string[]): string{
let output = names.join(delimiter)
return output
}
Within Foundry, the function above ends up only having two inputs: delimiter (string) and names (array).
Does anyone have any working functions in Foundry with n number of input parameters?
Upvotes: 3
Views: 158
Reputation: 37177
Unfortunately it's not possible at the moment. Functions need to have deterministic pre-defined inputs and outputs. Using rest operator makes the number of inputs non predictable, so it's not supported at the moment.
A work around would be to have multiple functions with different inputs, but it doesn't look very clean.
public stringAppendFunction(delimiter: string, ...names: string[]): string{
let output = names.join(delimiter)
return output
}
@Function()
public stringAppendFunction1P(delimiter: string, name1: string): string{
return this.stringAppendFunction(delimiter, name1)
}
@Function()
public stringAppendFunction2P(delimiter: string, name1: string, name2: string): string{
return this.stringAppendFunction(delimiter, name1, name2)
}
Upvotes: 2