Skip to content

Instantly share code, notes, and snippets.

@ice1000
Created August 24, 2017 14:50
Show Gist options
  • Save ice1000/8063007602008da63e763b73f4d55671 to your computer and use it in GitHub Desktop.
Save ice1000/8063007602008da63e763b73f4d55671 to your computer and use it in GitHub Desktop.
function composition
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