This file contains hidden or 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
val doubler = multiplier(2) | |
print(doubler(5.6)) // 11.2 |
This file contains hidden or 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
fun multiplier(factor: Double): (Double) -> Double = { number -> number*factor } |
This file contains hidden or 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
circleOperation(5.3, { (2 * Math.PI) * it }) |
This file contains hidden or 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
print(circleOperation(3.0, ::calArea)) // 28.274333882308138 | |
print(circleOperation(3.0, calArea)) // won't compile | |
print(circleOperation(3.0, calArea())) // won't compile | |
print(circleOperation(6.7, ::calCircumference)) // 42.09734155810323 |
This file contains hidden or 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
fun calCircumference(radius: Double) = (2 * Math.PI) * radius | |
fun calArea(radius: Double): Double = (Math.PI) * Math.pow(radius, 2.0) | |
fun circleOperation(radius: Double, op: (Double) -> Double): Double { | |
val result = op(radius) | |
return result | |
} |
This file contains hidden or 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
val sum: (Int, Int) -> Int = { x, y -> x + y } | |
val action: () -> Unit = { println(42) } |
This file contains hidden or 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
val action: () -> Unit = { println(42) } |
This file contains hidden or 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
val sum: (Int, Int) -> Int = { x, y -> x + y } |
This file contains hidden or 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
val sum = { x: Int, y: Int -> x + y } | |
val action = { println(42) } |
This file contains hidden or 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
list.filter { x > 0 } |