tags:

views:

214

answers:

1

I'm hoping there is a way to define a type for a function in Scala.

For example, say I want a function that takes two Ints and returns a Boolean, I could define a function that uses that like this:

def checkInts(f: (Int,Int) => Boolean) = {
  // do stuff
}

Is there a way to define the type of f? Then I could do something like:

def checkInts(f: MyFunctionType)

or

def checkInts(f: Option[MyFunctionType])
+10  A: 
trait Foo {
  type MyFunction = (Int,Int) => Boolean

  def checkInts(f: MyFunction)
  def checkInts(f: Option[MyFunction])
}
Mitch Blevins
Perfect, thanks Mitch.
Alex Black