Is it possible to make inline functions that do not require all of the parameter inputs?
-
As in
inline function doSomething(parameter1, parameter2)
then if you write
doSomething(10)
It could carry on and work without that explicit input of the 2nd parameter?
I noticed there are methods in the API that work like this (where some parameters are optional) and wondering if this is possible for the inline functions.
When I test this:
inline function doSomething(parameter1, parameter2) { return parameter1; } const testDS = doSomething(10); Console.print(testDS);
I get:
Inline function call doSomething: parameter amount mismatch: 1 (Expected: 2)
-
@VirtualVirgin It's not possible to have them with optional arguments. What you can do though is just pass one argument that's an object or an array, and within the function check if it contains the thing you're interested in
inline function myFunc(params) { if (isDefined(params.myKey1)) // Do something if (isDefined(params.myKey1)) // Do something else. }
-
@d-healey Clever!
-
For more complicated functions you could pass an array of parameters and branch to different functions based on the length of the array.
For example
inline function myFunc(params: Array) { switch (params.length) { case 0: return subFunc0(); case 1: return subFunc1(params[0]); case 2: return subFunc2(params[0], params[1]); case 3: return subFunc3(params[0], params[1], params[2]); } }