Module

Control.Select

Package
purescript-selective-functors
Repository
artemisSystem/purescript-selective-functors

#Select Source

class Select :: (Type -> Type) -> Constraintclass (Apply f) <= Select f  where

Select is an abstraction that sits between Apply and Bind.

Instances must satisfy the following law:

  • Associativity:
  x <*? (y <*? z) = ((map Right <$> x) <*? (f <$> y)) <*? uncurry z
  where
  f (Left y) x = Tuple y x
  f (Right y) x = y x

Members

Instances

#(<*?) Source

Operator alias for Control.Select.select (left-associative / precedence 4)

#selectM Source

selectM :: forall @m @a @b. Monad m => m (Either a b) -> m (a -> b) -> m b

select implemented in terms of bind and pure

#selectTM Source

selectTM :: forall @t @a @b. Traversable t => t (Either a b) -> t (a -> b) -> t b

select implemented in terms of sequence. With this implementation, depending on the Either in the first argument, the first or the second effect will be executed, but never both. Traversable allows us to inspect the Either in the first parameter without including its effect in the result. This implementation is well suited for array-like traversables. (i.e. potentially containing more than one element)

#selectTS Source

selectTS :: forall @f @a @b. Traversable f => Apply f => f (Either a b) -> f (a -> b) -> f b

select implemented in terms of sequence and apply. This implementation uses apply to keep the effects of the first parameter when it is a Left, unlike selectTM. This implementation is well suited for tuple-like traversables (i.e. containing one or fewer elements)

#selectA Source

selectA :: forall @f @a @b. Apply f => f (Either a b) -> f (a -> b) -> f b

select implemented in terms of apply (both effects are always executed)

#applyS Source

applyS :: forall @f @a @b. Select f => f (a -> b) -> f a -> f b

apply implemented in terms of select

#whenS Source

whenS :: forall @f. Select f => f Boolean -> f Unit -> f Unit

Execute the second action if the first action returns true

#unlessS Source

unlessS :: forall @f. Select f => f Boolean -> f Unit -> f Unit

Execute the second action if the first action returns false

#branch Source

branch :: forall @f @a @b @c. Select f => f (Either a b) -> f (a -> c) -> f (b -> c) -> f c

Execute either the second or the third action, depending on the result of the first

#ifS Source

ifS :: forall @f @a. Select f => f Boolean -> f a -> f a -> f a

If the first action is true, execute the second action, otherwise the third

#orS Source

orS :: forall @f. Select f => f Boolean -> f Boolean -> f Boolean

Short-circuiting or

#(<||>) Source

Operator alias for Control.Select.orS (right-associative / precedence 2)

#andS Source

andS :: forall @f. Select f => f Boolean -> f Boolean -> f Boolean

Short-circuiting and

#(<&&>) Source

Operator alias for Control.Select.andS (right-associative / precedence 3)

#any1S Source

any1S :: forall @t @f. Select f => Foldable1 t => t (f Boolean) -> f Boolean

Short-circuiting any

#all1S Source

all1S :: forall @t @f. Select f => Foldable1 t => t (f Boolean) -> f Boolean

Short-circuiting all

#fromMaybeS Source

fromMaybeS :: forall @f @a. Select f => f a -> f (Maybe a) -> f a

If the second action is Nothing, run and return the first

#whileS Source

whileS :: forall @f. Lazy (f Unit) => Select f => f Boolean -> f Unit

Repeat an action until it returns true