Marcus Ilgner
01/22/2024, 11:20 AMIor.Left
? I have an existing value using which I want to transform a subsequent Ior.Left
into an Ior.Both
- but all the approaches I have found look quite clumsy.
I prefer using the Raise DSL so my expression currently looks like this:
ior({ a, _ -> a }) { // this simple scenario only produces one relevant Left value
val result = op1ReturnsEither().bind()
op2ReturnsIor().fold( // the Right side of this operation in this context will be the same as result from op1, so it can be ignored.
fa = { Ior.Both(it, result) },
fb = { Ior.Right(result) },
fab = { err, _ -> Ior.Both(err, result) }
)
}.flatten { a, _ -> a } // same issue as above
I'm pretty sure there is a better - i.e. more concise or idiomatic - way, so I'm looking forward to suggestions.