pablisco
06/16/2021, 1:56 PMnullable {}
option {}
either {}
I can see two problems with this:
• relatively easy to clash those names with local variables
• Hard to discover them
Should we do something like:
bindingToNullable {}
bindingToOption {}
bindingToEither {}
This one would work nicely with autocomplete to give nice discoverability.
Any thoughts? 🙂Imran/Malic
06/17/2021, 11:46 AMimport as
. But I am in favor of the existing names, because it implies that the result of the computation within leads to an Either, Option or nullablepablisco
06/17/2021, 12:00 PMxxxToOption
does imply that the computation within results in an Option, doesn't it?pablisco
06/18/2021, 10:12 AMcomputeToNullable {}
computeToOption {}
computerToEither {}
Also, as a separate note we could probably have separate eager versions:
computeEagerlyToNullable {}
computeEagerlyToOption {}
computerEagerlyToEither {}
pablisco
06/19/2021, 6:54 PMval c = compute {
val a = sourceOfA.bind()
val b = sourceOfB.bind()
endWithEitherOf<Throwable, String>(a + b)
}
Or
val c = compute {
val a = sourceOfA.bind()
val b = sourceOfB.bind()
endWithNullableOf<String>(a + b)
}
So, the final call, which returns a token value type that cannot be instantiated outside of the scope, defines the type of the computationpablisco
06/19/2021, 7:18 PMpablisco
06/19/2021, 9:57 PMImran/Malic
06/19/2021, 10:26 PMraulraja
06/21/2021, 7:53 AMbind
is used in the body and the block can only infer based on arguments or return.pablisco
06/21/2021, 9:48 AMOption, nullable -> Either<Unit, A>
Result -> Either<Throwable, A>
which means that potentially we could have a ComputeScope:
interface ComputeScope<E, A> {
fun Either<E, A>.bind(): A
}
With scoped extensions:
context(ComputeScope<Unit, A>)
fun <A> A?.bind(): A
context(ComputeScope<Throwable, A>)
fun <A> Result<A>.bind(): A
Hopefully this should add the right type without explicit type definition.
And then we can do a conversion at the end into the type that we want.
But yeah, not quite ready for this as it is now 😅pablisco
06/21/2021, 9:57 AMflow {}