Richard Schielek
10/31/2024, 5:37 PMIor
type.
Let's say I have some code that needs to be resilient but should log unexpected behavior:
fun foo(): Int {
println("Something unexpected happened and I want to proceed")
println("Another unexpected thing happened and I still want to proceed")
return 42
}
I want my function to have no side-effects to be able to test it more thoroughly. Ior
seems to be a perfect match, but I am quite unhappy how my code turns out.
fun foo2(): Ior<NonEmptyList<String>, Int> = iorNel {
Ior.Both("Something unexpected happened but I still want to proceed".nel(), Unit).bind()
Ior.Both("Another unexpected thing happened but I still want to proceed".nel(), Unit).bind()
42
}
Is there a better way of writing this?Richard Schielek
10/31/2024, 6:12 PM@RaiseDSL
fun <E> IorRaise<NonEmptyList<E>>.raiseAndContinue(error: E) {
Ior.Both(error.nel(), Unit).bind()
}
Stylianos Gakis
10/31/2024, 6:25 PMRichard Schielek
10/31/2024, 6:55 PMStylianos Gakis
10/31/2024, 7:34 PM