0

Take below function as example:

val increment: (Int) => (Int) = (x) => (x+1)

How could this be used as function Type? or more specifically why such implementation is called function Type? How is it more beneficial than the below implementation of function?

def increment(x: Int): Int = x + 1
cchantep
  • 9,118
  • 3
  • 30
  • 41
user3400887
  • 409
  • 1
  • 4
  • 18
  • The second one is a method, not a function. Can you clarify your question? – Jörg W Mittag Jun 07 '15 at 13:17
  • First, your `def` didn't compile, then, ```scala> increment(_) ==> res1: Int => Int = ``` – cchantep Jun 07 '15 at 13:20
  • I think you got something wrong here. Function Type is the type of the function, in this case Int => Int meaning this is function that takes an Int and returns an Int. Maybe you mean the use of anonymous functions (function literals) compared to normal functions (defined using `def`)? – marios Jun 07 '15 at 16:26
  • 1
    possible duplicate of [What is a function literal in Scala?](http://stackoverflow.com/questions/5241147/what-is-a-function-literal-in-scala) – marios Jun 07 '15 at 16:34
  • @marios Thanks for sharing the link. It was helpful. – user3400887 Jun 07 '15 at 18:15

0 Answers0