Module

Control.Plus

Package
purescript-control
Repository
purescript/purescript-control

#Plus Source

class (Alt f) <= Plus f  where

The Plus type class extends the Alt type class with a value that should be the left and right identity for (<|>).

It is similar to Monoid, except that it applies to types of kind * -> *, like Array or List, rather than concrete types like String or Number.

Plus instances should satisfy the following laws:

  • Left identity: empty <|> x == x
  • Right identity: x <|> empty == x
  • Annihilation: f <$> empty == empty

Members

Instances

Re-exports from Control.Alt

#Alt Source

class (Functor f) <= Alt f  where

The Alt type class identifies an associative operation on a type constructor. It is similar to Semigroup, except that it applies to types of kind * -> *, like Array or List, rather than concrete types String or Number.

Alt instances are required to satisfy the following laws:

  • Associativity: (x <|> y) <|> z == x <|> (y <|> z)
  • Distributivity: f <$> (x <|> y) == (f <$> x) <|> (f <$> y)

For example, the Array ([]) type is an instance of Alt, where (<|>) is defined to be concatenation.

Members

  • alt :: forall a. f a -> f a -> f a

Instances

#(<|>) Source

Operator alias for Control.Alt.alt (left-associative / precedence 3)

Re-exports from Data.Functor

#Functor Source

class Functor f  where

A Functor is a type constructor which supports a mapping operation map.

map can be used to turn functions a -> b into functions f a -> f b whose argument and return types use the type constructor f to represent some computational context.

Instances must satisfy the following laws:

  • Identity: map identity = identity
  • Composition: map (f <<< g) = map f <<< map g

Members

  • map :: forall b a. (a -> b) -> f a -> f b

Instances

#void Source

void :: forall a f. Functor f => f a -> f Unit

The void function is used to ignore the type wrapped by a Functor, replacing it with Unit and keeping only the type information provided by the type constructor itself.

void is often useful when using do notation to change the return type of a monadic computation:

main = forE 1 10 \n -> void do
  print n
  print (n * n)

#(<$>) Source

Operator alias for Data.Functor.map (left-associative / precedence 4)

#(<$) Source

Operator alias for Data.Functor.voidRight (left-associative / precedence 4)

#(<#>) Source

Operator alias for Data.Functor.mapFlipped (left-associative / precedence 1)

#($>) Source

Operator alias for Data.Functor.voidLeft (left-associative / precedence 4)