Selective
is a typeclass to represent a composition of two independent effectful computations.
Selective
includes all combinators present in Applicative
.
Select applies an effectful computation wrapped in a Kind<F, (A) -> B>
that will be applied to the datatype for one of its branches.
import arrow.core.*
import arrow.core.extensions.*
import arrow.fx.*
Some<Either<Int, String>>(Left(1))
.select(Some({ a: Int -> a.toString() }))
// Option.Some(1)
Some<Either<Int, String>>(Right("2"))
.select(Some({ a: Int -> a.toString() }))
// Option.Some(2)
Arrow provides SelectiveLaws
in the form of test cases for internal verification of lawful instances and third party apps creating their own Selective instances.
Selective
instancesArrow already provides Selective
instances for most common datatypes both in Arrow and the Kotlin stdlib.
See Deriving and creating custom typeclass to provide your own Selective
instances for custom datatypes.
Do you like Arrow?
✖