Module
Data.Functor
- Package
- purescript-prelude
- Repository
- purescript/purescript-prelude
#Functor Source
class Functor :: (Type -> Type) -> Constraint
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 a b. (a -> b) -> f a -> f b
Instances
#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
#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)
#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)
- Modules
- Control.
Applicative - Control.
Apply - Control.
Bind - Control.
Category - Control.
Monad - Control.
Semigroupoid - Data.
Boolean - Data.
BooleanAlgebra - Data.
Bounded - Data.
Bounded. Generic - Data.
CommutativeRing - Data.
DivisionRing - Data.
Eq - Data.
Eq. Generic - Data.
EuclideanRing - Data.
Field - Data.
Function - Data.
Functor - Data.
Generic. Rep - Data.
HeytingAlgebra - Data.
HeytingAlgebra. Generic - Data.
Monoid - Data.
Monoid. Additive - Data.
Monoid. Conj - Data.
Monoid. Disj - Data.
Monoid. Dual - Data.
Monoid. Endo - Data.
Monoid. Generic - Data.
Monoid. Multiplicative - Data.
NaturalTransformation - Data.
Ord - Data.
Ord. Generic - Data.
Ordering - Data.
Reflectable - Data.
Ring - Data.
Ring. Generic - Data.
Semigroup - Data.
Semigroup. First - Data.
Semigroup. Generic - Data.
Semigroup. Last - Data.
Semiring - Data.
Semiring. Generic - Data.
Show - Data.
Show. Generic - Data.
Symbol - Data.
Unit - Data.
Void - Prelude
- Record.
Unsafe - Type.
Proxy