Created
January 23, 2021 12:07
-
-
Save christianb/4c5e23279aa6f01de44b9ab925967b90 to your computer and use it in GitHub Desktop.
Pipe function in Kotlin
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
// 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