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
fabA computation that results in an
Eithervalue.fA 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
condA computation evaluating to a boolean value.
thenA 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
fabComputation producing an
Eithervalue, to decide which computation is executed afterwards.ifLeftComputation that will be executed if
fabevaluates to anEither.leftvalue.ifRightComputation that will be executed if
fabevaluates to anEither.rightvalue.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
xComputation producing a boolean value to decide which computation is exectured afterwards.
thenComputation that will be executed if the first evaluates to
true.elseComputation 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
xDefault value for the empty case.
mxA 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
pA lifted predicate to find any element of the
arraythat matches it.arrayAn 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
pA lifted predicate to check all elements of the
arraymatch it.arrayAn 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
Install in Dash
Selective Protocol Reference