Ben Butterworth
08/21/2020, 9:55 PMscope.launch{}
, what do you call those curly braces? I know the last parameter type seems to have to be a lambda, often called block
nanodeath
08/21/2020, 10:06 PMfun launch(callback: () -> Unit)
, aka fun launch(callback: Function1<Unit, Unit>)
...I think.I know the last parameter type seems to have to be a lambda, often calledI mean, this seems accurateblock
Ben Butterworth
08/21/2020, 10:10 PM->
it
, but its actually this
this
is the receiver argument, and it
is the first argument of the lambda. https://stackoverflow.com/questions/60485368/kotlin-difference-between-it-and-this-keywordnanodeath
08/21/2020, 10:17 PMCoroutineScope.() -> Unit
is as much a lambda as (Int) -> Double
isBen Butterworth
08/21/2020, 10:19 PMnanodeath
08/21/2020, 10:20 PMBen Butterworth
08/21/2020, 10:20 PMnanodeath
08/21/2020, 10:23 PMBen Butterworth
08/21/2020, 10:36 PMthis
is applicable to all functions that take a lambda with receiver, not just scope functions
Scope functions: There are five such functions included in the Kotlin standard library:https://kotlinlang.org/docs/reference/scope-functions.html Edit: Edited with official link,apply
,run
,with
, andlet
.also
brandonmcansh
08/22/2020, 3:04 AMCoroutineScope.() -> Unit
is an example of the use of the optional receiver type (CoroutineScope in this example) with the block/function being called on the receiver as opposed to (CoroutineScope) -> Unit
Dennis
08/22/2020, 2:03 PMBen Butterworth
08/22/2020, 7:03 PMcaelum19
08/28/2020, 4:04 PMBen Butterworth
11/04/2020, 10:30 PM