```inline fun <T> T.scope(block: T.() -> ...
# ktor
b
Copy code
inline 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
👍 1
Copy code
class 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)
}
Particularly handy if you want to utilize a DSL directly inside a function declaration that returns
Unit
and want to avoid extra nesting
Copy code
override fun invoke(app: Application) {
    app.run {
        authentication { ... }
        routing { ... }
    }
}
T.scope
probably describes better what it’s purpose is rather than what it returns
Copy code
val list = listOf("one", "two", "three")
list.scope {
    forEach {
        println("item: $it")
    }

    map(String::capitalize).forEach(::println)

    ...
}