Module

Data.Functor

Package
purescript-prelude
Repository
purescript/purescript-prelude

#Functor Source

class Functor :: (Type -> Type) -> Constraintclass 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 a b. (a -> b) -> f a -> f b

Instances

#(<$>) Source

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

#mapFlipped Source

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)

#void Source

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)

#voidRight Source

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)

#voidLeft Source

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

A version of voidRight with its arguments flipped.

#($>) Source

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

#flap Source

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

Apply a value in a computational context to a value in no context.

Generalizes flip.

longEnough :: String -> Bool
hasSymbol :: String -> Bool
hasDigit :: String -> Bool
password :: String

validate :: String -> Array Bool
validate = flap [longEnough, hasSymbol, hasDigit]
flap (-) 3 4 == 1
threeve <$> Just 1 <@> 'a' <*> Just true == Just (threeve 1 'a' true)

#(<@>) Source

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