Docs for the spread operator: <https://helpx.adobe...
# adobe
a
Docs for the spread operator: https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-lang[…]xpressions-and-number-signs/expressions-developing-guide.html Code:
Copy code
function pow(required numeric base, required numeric exponent) {
    return base ^ exponent
}

// control - normal call
writeOutput(pow(2,3)) // 8
writeOutput("<hr>")


//using array
operandsAsArray = [2,3]
writeOutput(pow(...operandsAsArray)) // 8
writeOutput("<hr>")


// using struct
operandsAsStruct = {
    base = 2,
    exponent = 3
}
try {
    writeDump(pow(...operandsAsStruct)) // splat
} catch (any e) {
    writeDump([
        type = e.type, // Application
        message = e.message // The BASE argument passed to the pow function is not of type numeric.
    ])
}

function argTypeCheck(x, y) {
    writeDump([
        arguments = arguments,
        "x.type" = x.getClass().getName(),
        "x.key" = x.getKey(),
        "x.value" = x.getValue()
    ])
}

st = {
    x = 2,
    y = "three"
}
argTypeCheck(...st) // WTaF
https://trycf.com/gist/062dfa6d4651304929c6e144588fd8bf/acf2021?theme=monokai Result:

https://i2.paste.pics/d098bdd981455e4a5db9f5395e860092.png

What's going on with the struct there, @Mark Takata (Adobe)? Well: I know what's going on... the "iterable object" is just being thrown at the function instead of the elements of it as per the array example. Why would that be something that happens, instead of the struct elements being applied as named args, equiv to the array version being applied to positional ones?
NB @Simone... this is how to provide a starting point for a question about code one doesn't understand. Runnable code demonstrating the issue; showing the output of the code running; clearly (I hope) describing the issue; laying out my expectations.