Hey Guys, need some help. I have multiple Either’s and I want to collect the right from all of them to build an object. Something like this, but I’m not able to make this work:
@Test
fun combineEithers() {
val name = randomEither(null, "Alfredo Lambda")
val phone = randomEither(null, 55555555)
val address = randomEither(null, listOf("1 Main Street", "11130", "NYC"))
val result = Either.applicative<Profile>()
.tupled(name, phone, address)
.fix()
.map { Profile(it.a, it.b, it.c) }
println(result)
}
fun <K> randomEither(left: ResponseError?, right: K): Either<ResponseError, K> {
return if (left != null) {
Either.left(left)
} else {
Either.right(right)
}
}
data class Profile(val name: String, val phone: Int, val address: List<String>)