CLOVIS
03/08/2021, 10:01 PMrequire()
, check()
and error()
to shortcut execution. Either is much more “precise” and “safe”, however I don't know how to write something as concise and readable:
fun foo(param: Int) {
require(param > 1) { "Some message here" }
doSomething() ?: error("that's not possible")
}
I guess the either
block should help with this, but I don't really see how to use it for these cases.CLOVIS
03/08/2021, 10:03 PMfun <L> requireEither(cond: Boolean, block: () -> L): Either<L, Unit> =
if (cond) Right(Unit)
else Left(block())
This function would be used in an either
block exactly as the current require
function is used.
Obviously the name is bad, but apart from that, what do you think?CLOVIS
03/09/2021, 8:23 AMinline
as well, but yeah I'd love to have access to those ^^simon.vergauwen
03/09/2021, 8:29 AMsimon.vergauwen
03/09/2021, 8:29 AMCLOVIS
03/09/2021, 9:13 AMeither
I would've used early returns, but those are not available everywhere (inside crossinline
lambdas for example)simon.vergauwen
03/09/2021, 9:18 AMsimon.vergauwen
07/19/2021, 5:28 PMCLOVIS
07/19/2021, 5:33 PMsimon.vergauwen
07/19/2021, 5:40 PM