Skip to content

Instantly share code, notes, and snippets.

@christianb
Created January 23, 2021 12:07
Show Gist options
  • Save christianb/4c5e23279aa6f01de44b9ab925967b90 to your computer and use it in GitHub Desktop.
Save christianb/4c5e23279aa6f01de44b9ab925967b90 to your computer and use it in GitHub Desktop.
Pipe function in Kotlin
// From https://discuss.kotlinlang.org/t/pipe-forward-operator/2098/22
// Showes how to implement a pipe function in Kotlin
infix fun <T, R> T.into(func: (T) -> R) = func(this)
// How to use
fun add(x: Int): Int = x + 1
fun mul(x: Int): Int = x * 12
fun main() {
println(5 into ::add into ::mul)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment