CLOVIS
06/07/2021, 3:39 PMeither
block?
I currently have:
if (some condition) {
val left: Either<Failure, DbUser> =
UnknownFailure("some message here")
.left()
left.bind()
}
I would have just written
if (some condition)
UnknownFailure("message").left().bind()
however, that casts the entire either block to Either<Failure, Nothing>.
Cody Mikol
06/07/2021, 3:46 PMCLOVIS
06/07/2021, 3:49 PMRight
. Unless I make it have a Right(Unit)
, but that doesn't seem that cleanCody Mikol
06/07/2021, 3:49 PMCody Mikol
06/07/2021, 3:50 PM.void()
Cody Mikol
06/07/2021, 3:51 PMEither.conditionally(condition, {err}, {Unit}).bind()
Cody Mikol
06/07/2021, 3:55 PMfun validateCondition(foo: Foo) = Either.conditionally(foo.isValid, {UnknownFailure("bar")}, {Unit})
kierans777
06/08/2021, 3:49 AMif
statements. Passing functions to functions like Either.conditionally
is the way to make the code cleaner.