Created
August 24, 2017 14:50
-
-
Save ice1000/8063007602008da63e763b73f4d55671 to your computer and use it in GitHub Desktop.
function composition
This file contains hidden or 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
operator fun <A, B, C> ((B) -> A).plus(p: (C) -> B) = { it: C -> this(p(it)) } | |
fun main(args: Array<String>) { | |
val a: (Int) -> String = { it.toString() } | |
val b: (String) -> ByteArray = { it.toByteArray() } | |
println((b + a)(233)) | |
val c: (ByteArray) -> List<Int> = { it.map { it.toInt() } } | |
println((c + b + a)(666)) // Haskell: c . b . a $ 666 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment