Created
January 15, 2016 07:15
-
-
Save hossshy/0fbcc089d440d02d73c8 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
package chapter4 | |
/** | |
* Created by hoshi on 1/15/16. | |
*/ | |
object MainObj { | |
val areaOfRect: (Int, Int) => Int = (width: Int, height: Int) => { | |
width * height | |
} | |
// Same | |
val areaOfRect2: Function2[Int, Int, Int] = (width: Int, height: Int) => { | |
width * height | |
} | |
// Same | |
val areaOfRect3: (Int, Int) => Int = new Function2[Int, Int, Int] { | |
def apply(width: Int, height: Int): Int = { | |
width * height | |
} | |
} | |
def operation(functionparam : (Int, Int) => Int) { | |
println(functionparam(4,4)) | |
} | |
def main(args: Array[String]) { | |
println(areaOfRect(5, 3)) | |
println(areaOfRect2(5, 3)) | |
println(areaOfRect3(5, 3)) | |
var doubler = (i: Int) => { i * 2 } | |
println(doubler(5)) | |
val add = (x:Int, y:Int) => { x + y } | |
val sub = (x:Int, y:Int) => { x - y } | |
operation(add) | |
operation(sub) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment