tim
06/03/2020, 6:46 PMval a = Either.right(1)
val b = Either.right(2)
val c = Either.right(3)
val d = Either
.applicative<Nothing>()
.mapN(a, b, c) { (a, b, c) ->
listOf(a, b, c)
}
.fix()
.fold(
ifLeft = { println("try again :(") },
ifRight = { println("success: $it") }
)
But I'm now integrating it into my actual use case which is about parsing variables from a url pathjulian
06/03/2020, 6:49 PMtim
06/03/2020, 6:53 PMval a = getEither(1)
val b = getEither(2)
val c = getEither(3)
val d = Either
.applicative<Int>()
.mapN(a, b, c) { (a, b, c) ->
listOf(a, b, c)
}
.fix()
.fold(
ifLeft = { println("try again :(") },
ifRight = { println("success: $it") }
)
fun getEither(value: Int) : Either<String, Int> {
return if(Random.nextBoolean()) {
Either.left("ouch!")
} else {
Either.right(value)
}
}
tim
06/03/2020, 6:53 PMpakoito
06/03/2020, 6:53 PMEither.conditionally
pakoito
06/03/2020, 6:54 PMpakoito
06/03/2020, 6:54 PMpakoito
06/03/2020, 6:54 PMtim
06/03/2020, 6:56 PMtim
06/03/2020, 6:56 PMtim
06/03/2020, 6:57 PMtim
06/03/2020, 6:58 PM