Created
November 25, 2014 07:59
-
-
Save akiomik/2fda5699f7c3ce001670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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