https://kotlinlang.org logo
#arrow
Title
# arrow
g

Guido Wehner

10/17/2023, 1:48 PM
Is there a way to transform a Raise<NonEmptyList<Error>> to a Raise<Error>? We use the raise dsl to get config values or generate a ConfigurationError with a message. We split it up in multiple functions on Raise<NEL<ConfigError>>, but in the end I want to return a final Configuration with all subparts or raise one single Error with all the messages. I can hardly express that with the help of lots of Eithers, but not with Raise alone. Is there a way?
c

CLOVIS

10/17/2023, 1:53 PM
Copy code
class InputError
class OutputError(val errors: NonEmptyList<InputError>)

context(Raise<NonEmptyList<InputError>>)
fun bar() { … }

context(Raise<OutputError>)
fun foo() {
    withError(::OutputError) { 
        bar()
    }
}
https://apidocs.arrow-kt.io/arrow-core/arrow.core.raise/with-error.html
3 Views