I have function that returns an `Either` ``` fu...
# arrow
h
I have function that returns an
Either
Copy code
fun getConfigVersion(configId: ConfigId, versionId: ConfigVersionId): Either<DomainError, PIConfigVersion> {
        val configVersion = configVersionRepository.findByPiConfigModel_ProfileIdAndVersion(configId.id, versionId.id)
        return configVersion?.right() ?: NoVersionsFound("No ConfigVersion found for Config ${configId.id} and version ${versionId.id}").left()
    }
t
.bind() is only available within an either { ... } block i believe
h
Copy code
either.eager<DomainError, List<Policy>> {
                val piConfigVersion = getConfigVersion(evRequest.configId, evRequest.versionId).bind()
             
            }
is it something like this?
r
hi @Hareendran yes, also a few more examples here https://arrow-kt.io/docs/patterns/error_handling/#either
h
Thank you @raulraja.. got it to work …
related q: how can I convert
Copy code
List<Either<DomainError, Policy>>
to
Copy code
Either<DomainError, List< Policy>>>
I had something like
Copy code
results.sequence(Either.applicative()).fix().map { it.fix() }) {
            is Either.Left -> throw RuntimeException("There is an Error while saving incidents" + result.a)
            is Either.Right -> result.b
        }
but that doesn’t compile anymore with 1.0.1
r
those no longer need an applicative constraint and they are specialized per data type
there are also similar versions for
traverse
h
I’m slightly confused by that statement.. so how do. we go from
Copy code
List<Either<DomainError, Policy>>  to
Either<DomainError, List<Policy>>  to
r
Copy code
fun <E, A> Iterable<Either<E, A».sequenceEither(): Either<E, List<A»
it would be in that case calling
sequenceEither
in the collection
https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core/traverse-either.html is the same but applying the identity function. If in addition to flipping the types you want to apply a transformation you would use
traverseEither
instead.
h
Aha that is easier thank you
👍 1