def multi_fun(i:Int, s:String)(d:Double) […]
How to pass this function now to another function as an argument, i.e. which parameter type needs to be indicated?
def fun_that_likes_multi_fun(mf:(Int, String)(Double) ⇒ Unit) […]
This would not work, fails even to parse.
The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.
=> is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).
Luckily, you can write functions that take in more than one parameter by defining as many parameters as needed, for example: def function_name(data_1, data_2):
Currying in Scala is simply a technique or a process of transforming a function. This function takes multiple arguments into a function that takes single argument. It is applied widely in multiple functional languages. Syntax. def function name(argument1, argument2) = operation.
def fun_that_likes_multi_fun(mf:(Int, String)=>Double => Unit)={}
The function you have mentioned is a curried function. Which means the result of applying the first argument list is another function that takes the second argument list to process in entirety. So it is represented as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With