asdf asdf
either
fun main() { val res = nonSuspendingEither { if (Random.nextBoolean()) shift(AuthResult.Success(534)) else AuthResult.Failure("Invalid") } println(res) } @RestrictsSuspension interface RestrictedEffectScope<E> : EffectScope<E> fun <E, A> nonSuspendingEither(closure: suspend RestrictedEffectScope<E>.() -> A): Either<E, A> { var result: Either<E, A>? = null val scope = object : RestrictedEffectScope<E> { override suspend fun <B> shift(r: E): B { result = Either.Left(r) return suspendCoroutine { /*no-op*/ } } } closure.startCoroutine(scope, Continuation(EmptyCoroutineContext) { result = Either.Right(it.getOrThrow()) }) return result!! }
simon.vergauwen
either.eager
@RestrictSuspension
inline fun
1.1.6-alpha.59
A modern programming language that makes developers happier.