Nezteb
08/06/2019, 6:18 PMinline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
}
inline fun <T> T.also(block: (T) -> Unit): T {
block(this)
return this
}
inline fun <T> T.apply(block: T.() -> Unit): T {
block()
return this
}
inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
}
inline fun <T, R> T.run(block: T.() -> R): R {
return block()
}
What does the T.() -> R
imply? I know (T) -> R
is a function that takes a T
and returns an R
, but what does T.()
mean?LeoColman
08/06/2019, 6:19 PMartem_zin
08/06/2019, 6:19 PMLeoColman
08/06/2019, 6:19 PMthis
Shawn
08/06/2019, 6:23 PMT.() -> R
refers to a function that can be treated as a member of T
(and thus has this
defined in its scope as type T
), takes no arguments, and returns R
Nezteb
08/06/2019, 6:23 PMdave
08/06/2019, 8:10 PMdave
08/06/2019, 8:10 PMNezteb
08/06/2019, 8:45 PMstreetsofboston
08/06/2019, 10:10 PMAnimesh Sahu
08/07/2019, 2:33 AM