Module

Data.Functor.Contravariant

Package
contravariant
Repository
purescript/purescript-contravariant

#Contravariant Source

class Contravariant f  where

A Contravariant functor can be seen as a way of changing the input type of a consumer of input, in contrast to the standard covariant Functor that can be seen as a way of changing the output type of a producer of output.

Contravariant instances should satisfy the following laws:

  • Identity cmap id = id
  • Composition cmap f <<< cmap g = cmap (g <<< f)

Members

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

#(>$<) Source

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

#cmapFlipped Source

cmapFlipped :: forall f b a. Contravariant f => f a -> (b -> a) -> f b

cmapFlipped is cmap with its arguments reversed.

#(>#<) Source

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

#coerce Source

coerce :: forall b a f. Contravariant f => Functor f => f a -> f b

#imapC Source

imapC :: forall b a f. Contravariant f => (a -> b) -> (b -> a) -> f a -> f b

As all Contravariant functors are also trivially Invariant, this function can be used as the imap implementation for any types that have an existing Contravariant instance.