I want to convert an `Either<SomeError, SomeSuc...
# arrow
d
I want to convert an
Either<SomeError, SomeSuccess>
to a
SomeError?
, discarding the SomeSuccess. Does a function like that exist in arrow? Right now I'm just doing the below, but I wanted to know if there is a more idiomatic way
Copy code
return when (result) {
            is Either.Left -> result.a
            is Either.Right -> null
        }
d
e.swap().orNull() would give you what you’re looking for
d
Thank you! Also, is there a method like map for just doing a side effect? For example
Copy code
.mapForSideEffect { log(it) }
instead of
Copy code
.map { log(it); it }
d
Side effects?! 😱 😉 So that doesn’t exist in arrow core, but over in arrow fx where you pull in typeclasses that let you do this exact thing. You can read @raulraja’s explanation of this very thing here: https://github.com/arrow-kt/arrow/issues/1361#issuecomment-477113878
d
Thanks!
d
👍