Hugo
02/29/2020, 7:27 PM@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>)
raulraja
03/01/2020, 7:57 AMraulraja
03/01/2020, 7:57 AMraulraja
03/01/2020, 7:58 AMHugo
03/01/2020, 4:12 PM… short-circuits in left values preserving the first one found as the choosen one@raulraja This is exactly what I would like to accomplish but I can’t make it work.
Hugo
03/01/2020, 4:15 PM