Hi there. A question regarding
ior()
builder usage.
I have two functions:
important(): Either<Error, Something>
and
notSoImportant(): Either<Error, Unit>
and want to call them inside a
load(): Ior<Error, Something>
, that would return
Ior.Left
when
important()
fails, and
Both
if only
notSoImportant()
fails.
The only way I found to make this work is:
ior({ error, _ -> error }) {
val result = important().bind()
notSoImportant()
.fold(
{ Ior.Both(it, Unit) },
{ Ior.Right(it) }
)
.bind()
result
}
This feels a bit too verbose. Is there a better, more convenient way of doing this?