Module

Data.Functor

Package
purescript-prelude
Repository
purescript/purescript-prelude

#FunctorSource

class Functor f  where

A Functor is a type constructor which supports a mapping operation (<$>).

(<$>) 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: (<$>) id = id
  • Composition: (<$>) (f <<< g) = (f <$>) <<< (g <$>)

Members

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

Instances

#(<$>)Source

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

#mapFlippedSource

mapFlipped :: forall f a b. Functor f => f a -> (a -> b) -> f b

mapFlipped is map with its arguments reversed. For example:

[1, 2, 3] <#> \n -> n * n

#(<#>)Source

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

#voidSource

void :: forall f a. 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)

#voidRightSource

voidRight :: forall f a b. Functor f => a -> f b -> f a

Ignore the return value of a computation, using the specified return value instead.

#(<$)Source

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

#voidLeftSource

voidLeft :: forall f a b. Functor f => f a -> b -> f b

A version of voidLast with its arguments flipped.

#($>)Source

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