Egor Trutenko
10/30/2018, 1:34 PMapply
or let
) which return Unit
? Something like fun <T> T.end(block: T.() -> Unit): Unit
Vladyslav Sitalo
10/30/2018, 1:37 PMlet
or apply
?Egor Trutenko
10/30/2018, 1:39 PMfun returnsUnit() = doSomething.end { ... }
Instead of
fun returnsUnit() {
doSomething.apply { ... }
}
gildor
10/30/2018, 1:46 PMsindrenm
10/30/2018, 1:56 PMapply
or run
as I could essentially use either. 😛Egor Trutenko
10/30/2018, 1:57 PMend
in the end of an evaluation chain signalizes right away that the function doesn't return anything, moreover, such chains are more straightforward and are subjects to be lazified, if it's needed. But the best reason for such a question of me is still the same - there are a lot of cases when a function contains a single operator, which could be turned into single-line expression if only there was something like end
. Quick example - Glide's chainsUnit
, unfortunately ?:^)
gildor
10/30/2018, 2:00 PMEgor Trutenko
10/30/2018, 2:06 PMfun reloadImage() {
Glide.load(cachedUrl)
.asDrawable()
.apply(...)
.apply {
...
}
}
Does not seem to be really expressive and laconic, as Kotlin was intended to beuhe
10/30/2018, 2:55 PMasUnit()
or something like that to throw away the returned value in case you really want to use an expressiongildor
10/30/2018, 3:40 PMend
or asUnit
still require more focus to understanduhe
10/30/2018, 3:53 PM