Hi there. I am struggling a little with using the ...
# arrow
r
Hi there. I am struggling a little with using the
Ior
type. Let's say I have some code that needs to be resilient but should log unexpected behavior:
Copy code
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.
Copy code
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?
I mean I could introduce my own function:
Copy code
@RaiseDSL
fun <E> IorRaise<NonEmptyList<E>>.raiseAndContinue(error: E) {
    Ior.Both(error.nel(), Unit).bind()
}
r
Yes, that's exactly what I am looking for. So I just need to wait for 2.0 to drop and polyfill it myself in the meantime. Thank you very much.
s
No problem 😊