Gopal S Akshintala
03/16/2020, 5:25 AMmapN
which internally uses product
.
The below test passes: ✅
@Test
fun `Left * Right`() {
val product = Either.applicative<String>().run {
mapN(
"left".left(),
"right".right()
) {}
}.fix()
product.fold({ assertEquals("left", it) }, {})
}
But this one Fails, as it returns “left2”: 🛑
@Test
fun `Left * Right * Left`() {
val product = Either.applicative<String>().run {
mapN(
"left1".left(),
"right".right(),
"left2".left()
) {}
}.fix()
product.fold({ assertEquals("left1", it) }, {})
}
My expectation is to get the first left
instance, but it behaves to be returning the last left
instance. Is this behavior expected? If Yes, is there any other way I can get first left
instance? Thanks