Given the following curried function, what is the correct way to get a reference to curriedSum’s “second” function?
def curriedSum(x: Int)(y: Int) = x + y
Explanation
Get an explanation when it's available:
Theory
  • Consider the following curried function:
    def curriedSum(x: Int)(y: Int) = x + y
    
    There is a way to get an actual reference to curriedSum’s “second” function. You can use the placeholder notation to use curriedSum in a partially applied function expression, like this:
    scala> val onePlus = curriedSum(1)_
    onePlus: (Int) => Int = <function1>
    
    The underscore in curriedSum(1)_ is a placeholder for the second parameter list. The result is a reference to a function that, when invoked, adds one to its sole Int argument and returns the result:
    scala> onePlus(2)
    res7: Int = 3
    
    Read more: Currying

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести