Closed senky closed 5 years ago
@senky Quite right you are! 😄 Will fix this! What do you think, I believe the code could be even shorter with return array_sum($operands). If I'm correct, and please do tell me if I'm wrong, the ... in php take all the arguments and put them in an array so this array_sum should technically work. Still it would only work if parameters are numbers, otherwise a transformation function should be provided as a first parameter.
Hmmm now I'm a bit stumped, should I leave the example to work with numbers or should I expand it with a transformation function as well?
@petrovicstefanrs I wouldn't mix variadic functions with higher order functions. Also I wouldn't use array_sum
as it breaks all the wonder. 😅 But maybe you could add more semantics:
function variadicSum(...$operands)
...
@senky Welp I always forget that for a function to be a higher order function it only needs to accept a function as an argument not necessarily return a function as a result. (In my brain if it doesn't return a function its not a higher order function 😄) Anyway, keep it simple and change the name to actually mirror what the function does, okay like it! 😄
Hi,
variadicFunction
in PHP has quite wrong description and example. Variadic function is a function of any number of arguments. Not one argument of any length. So the code should look like:and an example: