experquisite
experquisite

Reputation: 879

fully applying functions in Scala, shorthand notation impossible?

Is there a way to declare a fully-applied function without a full new lambda?

scala> val F = (x: Int) => math.pow(x,2)
F: Int => Double = <function1>
scala> val G = F(3)
G: Double = 9.0

How can I declare it such that G is an:

() => Double = <function0>

Without doing this:

scala> val G = () => F(3)
G: () => Double = <function0>

? The _ notation doesn't seem to do the trick:

scala> val G = F(3) _
<console>:8: error: _ must follow method; cannot follow Double
       val G = F(3) _

Upvotes: 0

Views: 286

Answers (1)

sjrd
sjrd

Reputation: 22105

There is no way. The shortest form is what you came up with, i.e., () => F(3).

Upvotes: 1

Related Questions