aerialist
01/28/2019, 3:10 PMrun
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/run.html) which returns nothing (Unit
) (see code block).
towards
function purpose: run block()
in scope of T
. And if block()
returns some result - it must be ignored.
Kotlin-Dev Team, could you please recommend better name? And do you have plans to add same extension to language?
Thank you in advance.diesieben07
01/28/2019, 3:11 PMrun
.aerialist
01/28/2019, 3:13 PMnatpryce
01/28/2019, 3:14 PMrun
returns Unit, which (in Kotlin) is the same as returning no value.natpryce
01/28/2019, 3:15 PMtowards
function will return Unit. If you don’t explicitly declare a result type of a block-structured function, Kotlin defaults the result type to Unit.aerialist
01/28/2019, 3:15 PMnatpryce
01/28/2019, 3:17 PMrun
, and force the result of the towards
function to be Unit regardless?aerialist
01/28/2019, 3:22 PMtowards
function purpose: run block() in scope of T. And if block() returns some result - it must be ignored.natpryce
01/28/2019, 3:22 PMnatpryce
01/28/2019, 3:23 PMrun
?natpryce
01/28/2019, 3:25 PMaerialist
01/28/2019, 3:25 PMalllex
01/28/2019, 4:54 PMfunction purpose: run block() in scope of T. And if block() returns some result - it must be ignored.@aerialist It looks like you are giving a definition of a side-effect . So maybe try to think in that direction:
effect
or affect(ed)
, or runEffect
, etc.natpryce
01/28/2019, 5:02 PMalso
or apply
for side effects. The apply
extension method also discards any result from the block.natpryce
01/28/2019, 5:03 PMaerialist
01/29/2019, 8:20 AMapply
I can continue my work with object. In apply
docs: "... and returns this
value."
In case of towards
I have nothing to return and my work with object is finished.