First-class functions: Difference between revisions

Added Kotlin
mNo edit summary
(Added Kotlin)
Line 1,571:
Output:
<pre>0.5
0.4999999999999999
0.5000000000000001
</pre>
 
 
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
 
fun compose(f: (Double) -> Double, g: (Double) -> Double ): (Double) -> Double = { f(g(it)) }
 
fun cube(d: Double) = d * d * d
 
fun main(args: Array<String>) {
val listA = listOf(Math::sin, Math::cos, ::cube)
val listB = listOf(Math::asin, Math::acos, Math::cbrt)
val x = 0.5
for (i in 0..2) println(compose(listA[i], listB[i])(x))
}</lang>
 
{{out}}
<pre>
0.5
0.4999999999999999
0.5000000000000001
9,490

edits