Phani Mahesh
09/22/2020, 4:13 PMstreetsofboston
09/22/2020, 4:20 PMPhani Mahesh
09/22/2020, 4:20 PMraulraja
09/22/2020, 4:25 PM(A) -> B
is not the same type as suspend (A) -> B
since the latter becomes (A, Continuation<B>) -> Unit
streetsofboston
09/22/2020, 4:26 PMandThen
functions (and others) for suspend
funs. You could write your own 🙂raulraja
09/22/2020, 4:26 PMPhani Mahesh
09/22/2020, 4:27 PMfun <X, Y, Z> compose(f: (X) -> Y, g: (Y) -> Z): (X) -> Z = { x -> g(f(x)) }
suspend fun <X, Y, Z> compose(f: suspend (X) -> Y, g: suspend (Y) -> Z): suspend (X) -> Z = { x -> g(f(x)) }
suspend fun <X, Y, Z> compose(f: (X) -> Y, g: suspend (Y) -> Z): suspend (X) -> Z = { x -> g(f(x)) }
suspend fun <X, Y, Z> compose(f: suspend (X) -> Y, g: (Y) -> Z): suspend (X) -> Z = { x -> g(f(x)) }
// Syntax sugar for `g after f` notation.
infix fun <X, Y, Z> ((Y) -> Z).after(f: (X) -> Y): (X) -> Z = compose(f, this)
suspend infix fun <X, Y, Z> (suspend (Y) -> Z).after(f: suspend (X) -> Y): suspend (X) -> Z = compose(f, this)
suspend infix fun <X, Y, Z> ((Y) -> Z).after(f: suspend (X) -> Y): suspend (X) -> Z = compose(f, this)
suspend infix fun <X, Y, Z> (suspend (Y) -> Z).after(f:(X) -> Y): suspend (X) -> Z = compose(f, this)
// Syntax sugar for f andThen g notation.
infix fun <X, Y, Z> ((X) -> Y).andThen(g: (Y) -> Z): (X) -> Z = compose(this, g)
suspend infix fun <X, Y, Z> (suspend (X) -> Y).andThen(g: suspend (Y) -> Z): suspend (X) -> Z = compose(this, g)
suspend infix fun <X, Y, Z> ((X) -> Y).andThen(g: suspend (Y) -> Z): suspend (X) -> Z = compose(this, g)
suspend infix fun <X, Y, Z> (suspend (X) -> Y).andThen(g:(Y) -> Z): suspend (X) -> Z = compose(this, g)
raulraja
09/22/2020, 4:27 PMstreetsofboston
09/22/2020, 4:27 PMandThen
and others to make the available for both suspend and regular functions?raulraja
09/22/2020, 4:28 PMPhani Mahesh
09/22/2020, 4:28 PMPhani Mahesh
09/22/2020, 4:29 PMraulraja
09/22/2020, 4:29 PMPhani Mahesh
09/22/2020, 4:30 PMraulraja
09/22/2020, 4:30 PMPhani Mahesh
09/22/2020, 4:30 PM::getUserFromDb andThen ::getDisplayName
raulraja
09/22/2020, 4:31 PMPhani Mahesh
09/22/2020, 4:31 PMraulraja
09/22/2020, 4:34 PMraulraja
09/22/2020, 4:34 PMPhani Mahesh
09/22/2020, 4:39 PMsimon.vergauwen
09/23/2020, 2:27 PMinline
doens't work here since in the end you're wrapping in a regular lambda which is where the inlining stops. So you still need to duplicate the non-suspending and suspending syntax, so you can wrap in a regular -and a suspend lambda.