Given the following function,
def sum(a: Int, b: Int) = a + b
Select all correct ways to store function in a variable.
Explanation
Get an explanation when it's available:
Theory
  • A partially applied function is an expression in which you don't supply all of the arguments needed by the function. Instead, you supply some, or none, of the needed arguments. For example, to create a partially applied function expression involving sum,
    scala> def sum(a: Int, b: Int, c: Int) = a + b + c
    sum: (a: Int,b: Int,c: Int)Int
    
    in which you supply none of the three required arguments, you just place an underscore after "sum". The resulting function can then be stored in a variable. Here's an example:
    scala> val a = sum _
    a: (Int, Int, Int) => Int = 
    
    Read more: Partially applied functions

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes