Selective
public protocol Selective : Applicative
The Selective typeclass represents Selective Applicative Functors, described in this paper. Selective Applicative Functors enrich Applicative Functors by providing an operation that composes two effectful computations where the second depends on the first.
-
Conditionally applies the second computation based on the result of the first.
Declaration
Parameters
fab
A computation that results in an
Either
value.f
A computation that is executed in case the first computation evaluates to a left value.
Return Value
Composition of the two computations.
-
whenS(_:then:)
Extension methodEvaluates the second computation when the first evaluates to
true
.Declaration
Parameters
cond
A computation evaluating to a boolean value.
then
A computation that will be evaluated if the first computation evaluates to
true
.Return Value
Composition of the two computations.
-
branch(_:ifLeft:ifRight:)
Extension methodEvaluates one out of two computations based on the result of another computation.
Declaration
Parameters
fab
Computation producing an
Either
value, to decide which computation is executed afterwards.ifLeft
Computation that will be executed if
fab
evaluates to anEither.left
value.ifRight
Computation that will be executed if
fab
evaluates to anEither.right
value.Return Value
Composition of the computations.
-
ifS(_:then:else:)
Extension methodEvaluates one out of two computations based on the result of another computation.
Declaration
Parameters
x
Computation producing a boolean value to decide which computation is exectured afterwards.
then
Computation that will be executed if the first evaluates to
true
.else
Computation that will be executed if the first evaluates to
false
.Return Value
Composition of the computations.
-
orS(_:_:)
Extension method -
andS(_:_:)
Extension method -
fromOptionS(_:_:)
Extension methodEvaluates an optional computation, providing a default value for the empty case.
Declaration
Parameters
x
Default value for the empty case.
mx
A computation resulting in an optional value.
Return Value
Composition of the two computations.
-
anyS(_:_:)
Extension methodA lifted version of
any
. Retains the short-circuiting behavior.Declaration
Parameters
p
A lifted predicate to find any element of the
array
that matches it.array
An array to look for an element that matches the predicate in.
Return Value
A boolean computation describing if any element of the array matches the predicate.
-
allS(_:_:)
Extension methodA lifted version of
all
. Retains the short-circuiting behavior.Declaration
Parameters
p
A lifted predicate to check all elements of the
array
match it.array
An array to check if all elements match the predicate.
Return Value
A boolean computation describing if all elements of the array match the predicate.
-
whileS(_:)
Extension method