Function composition: Difference between revisions

m
→‎{{header|Kotlin}}: made compose function generic
m (→‎{{header|Kotlin}}: made compose function generic)
Line 1,743:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scalakotlin">// version 1.0.6
 
fun f(x: Int): Int = x * x
 
fun g(x: Int): Int = x + 2
 
fun <T, V, R> compose(f: (IntV) -> IntR, g: (IntT) -> IntV): (IntT) -> IntR = { f(g(it)) }
 
fun main(args: Array<String>) {
val x = 10
println(compose(::f, ::g)(x))
}</syntaxhighlight>
32

edits