bdawg.io
08/03/2018, 9:16 PMinline fun <T> T.scope(block: T.() -> Unit) {
block()
}
it’s `T.run`/`T.apply` without a return value
Edit: moved examples to thread to clean up channel feed
Edit: renamed extension function from unit
to scope
bdawg.io
08/03/2018, 9:49 PMclass MyKtorService : (Application) -> Unit {
override fun invoke(app: Application) = app.unit {
authentication { ... }
routing { ... }
}
}
fun main(args: Array<out String>) {
embeddedServer(Netty, module = dagger.myKtorService()).start(wait = true)
}
bdawg.io
08/03/2018, 9:49 PMUnit
and want to avoid extra nesting override fun invoke(app: Application) {
app.run {
authentication { ... }
routing { ... }
}
}
bdawg.io
08/03/2018, 10:34 PMT.scope
probably describes better what it’s purpose is rather than what it returns
val list = listOf("one", "two", "three")
list.scope {
forEach {
println("item: $it")
}
map(String::capitalize).forEach(::println)
...
}