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 blockBen Butterworth
08/21/2020, 10:01 PMBen Butterworth
08/21/2020, 10:02 PMnanodeath
08/21/2020, 10:06 PMnanodeath
08/21/2020, 10:07 PMfun launch(callback: () -> Unit), aka fun launch(callback: Function1<Unit, Unit>)...I think.nanodeath
08/21/2020, 10:07 PMI know the last parameter type seems to have to be a lambda, often calledÂI mean, this seems accurateblock
nanodeath
08/21/2020, 10:08 PMBen Butterworth
08/21/2020, 10:10 PM->Ben Butterworth
08/21/2020, 10:12 PMit, but its actually thisBen Butterworth
08/21/2020, 10:17 PMthis 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 PMnanodeath
08/21/2020, 10:18 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 PMBen Butterworth
08/21/2020, 10:21 PMnanodeath
08/21/2020, 10:23 PMnanodeath
08/21/2020, 10:24 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, andÂlet.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) -> UnitDennis
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