Last active
February 8, 2018 06:56
-
-
Save KucherenkoIhor/95e1c5e65404d45368490f293dd53ffb to your computer and use it in GitHub Desktop.
compising of functions with different types
This file contains 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 length(str: String): Int = str.length | |
fun strPlusX(x: Int): String = "string " + x | |
fun add6To(x: Int): Int = x + 6 | |
fun xMultipleX(x: Int): Int = x * x | |
operator fun <P1, R1, R2> ((R1) -> R2).plus(f: (P1) -> R1): (P1) -> R2 { | |
return {p1: P1 -> this(f(p1)) } | |
} | |
fun main(vars: Array<String>) { | |
val composed = ::length + ::strPlusX + ::add6To + ::xMultipleX // = ('string' + ((6 * 6) + 6)).length | |
println(composed(6)) // 9 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment