Data.Functor
#Functor
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
#(<$>)
Operator alias for Data.Functor.map (left-associative / precedence 4)
#mapFlipped
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
#(<#>)
Operator alias for Data.Functor.mapFlipped (left-associative / precedence 1)
#void
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
#(<$)
Operator alias for Data.Functor.voidRight (left-associative / precedence 4)
#voidLeft
#($>)
Operator alias for Data.Functor.voidLeft (left-associative / precedence 4)
#flap
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)
#(<@>)
Operator alias for Data.Functor.flap (left-associative / precedence 4)
Modules
- Control.Applicative
- Control.Apply
- Control.Bind
- Control.Category
- Control.Monad
- Control.Semigroupoid
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.CommutativeRing
- Data.DivisionRing
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Function
- Data.Functor
- Data.HeytingAlgebra
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Ord
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Last
- Data.Semiring
- Data.Show
- Data.Symbol
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Uncurried
- Effect.Unsafe
- Main
- PSCI.Support
- Prelude
- Prim
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Boolean
- Type.Data.Ordering
- Type.Data.Row
- Type.Data.RowList
- Type.Data.Symbol
- Type.Equality
- Type.Prelude
- Type.Proxy
- Type.Row
- Type.Row.Homogeneous