Fluent methods in Kotlin
suggest changeFluent methods in Kotlin can be the same as Java:
fun doSomething() {
someOtherAction()
return this
}
But you can also make them more functional by creating an extension function such as:
fun <T: Any> T.fluently(func: ()->Unit): T {
func()
return this
}
Which then allows more obviously fluent functions:
fun doSomething() {
return fluently { someOtherAction() }
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents