I wonder if there should be a variant in the EffectScope besides the existing suspend fun ensure(condition: Boolean, shift: () -> R): Unit, that expects a suspend () -> R function for shift.
Would this be possible? If not, what would be an elegant alternative to this?
s
simon.vergauwen
08/18/2022, 3:58 PM
Hey @Dirk,
This is definitely possible and the
suspend
marker should've probably been added there.
In the proposal for Arrow 2.0 it's either
inline
or will support
suspend
.
You can for now just copy the method, and turn it into a custom extension function that has the
suspend
marker.
simon.vergauwen
08/18/2022, 4:00 PM
Copy code
suspend fun <R> EffectScope<R>.ensure(condition: Boolean, shift: suspend () -> R): Unit =
if (condition) Unit else shift(shift())