Introduction
1 | fun MutableList<Int>.swap(index1: Int, index2: Int) { |
Example - Pipe
Arithmetics Version 1
1 | fun multiplyByTwo(x: Int): Int = x * 2 |
Arithmetics Version 2
1 | fun Int.addOne(): Int = this + 1 |
Arithmetics Version 3
1 | infix fun <T> T.then(func: (T) -> T): T = func(this) |
Arithmetics Version 4
1 | fun <T> T.pipe(vararg functions: (T) -> T): T { |
Reference
- [Kotlin pipeline syntax]https://medium.com/@krpiotrek/kotlin-pipeline-syntax-191b59429c38