Skip to content

Instantly share code, notes, and snippets.

@akiomik
Created November 25, 2014 07:59
Show Gist options
  • Save akiomik/2fda5699f7c3ce001670 to your computer and use it in GitHub Desktop.
Save akiomik/2fda5699f7c3ce001670 to your computer and use it in GitHub Desktop.
case class Calc(f: Int => Int, g: Int => Int, i: Int = 1) {
def calc: Int = (f compose g)(i)
}
object Calc {
def apply(f: Int => Int, g: Int => Int): Calc = new Calc(f, g)
}
// case class
val c1 = new Calc(_ * 10, _ + 10)
c1.calc // => 110
// case class
val c2 = Calc(_ * 10, _ + 10, 1)
c2.calc // => 110
// companion object
val c3 = Calc(_ * 10, _ + 10)
// <console>:12: error: missing parameter type for expanded function ((x$1) => x$1.$times(10))
// Calc(_ * 10, _ + 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment