Skip to content

Instantly share code, notes, and snippets.

View sajjadyousefnia's full-sized avatar
🤒
Out sick

Sajjad Yousefnia sajjadyousefnia

🤒
Out sick
View GitHub Profile
val doubler = multiplier(2)
print(doubler(5.6)) // 11.2
fun multiplier(factor: Double): (Double) -> Double = { number -> number*factor }
circleOperation(5.3, { (2 * Math.PI) * it })
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
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
}
val sum: (Int, Int) -> Int = { x, y -> x + y }
val action: () -> Unit = { println(42) }
val action: () -> Unit = { println(42) }
val sum: (Int, Int) -> Int = { x, y -> x + y }
val sum = { x: Int, y: Int -> x + y }
val action = { println(42) }
list.filter { x > 0 }