2019-02-02 00:18:33 Kotlin

関数型Kotlin ~関数合成編~

Copy Copied! Full
typealias Lambda<T, U> = (T)->U fun main(args: Array<String>) { println(({k:Int -> (k.toFloat()/5)} - {l: Int -> l*4+3})(6)) println(({k:Int -> (k*2).toString()} + {l: String -> "number: $l"})(6)) } infix operator fun<T, U, V> Lambda<T, U>.plus(other: Lambda<U, V>): Lambda<T, V> = { it: T -> other(this(it)) } infix operator fun<T, U, V> Lambda<T, U>.minus(other: Lambda<V, T>): Lambda<V, U> = { it: V -> this(other(it)) }
関数型Kotlin ~関数合成編~