functor-laws {monad} | R Documentation |
Functor Laws
Description
Classes implementing fmap()
are expected to satisfy two functor laws:
preservation of identity and preservation of composition.
Arguments
m |
A functor object. |
f , g |
Functions. |
Details
The Haskell functor laws can be translated into R as follows:
- Preservation of identity:
m %>>% identity
is equal tom |> identity()
.- Preservation of composition:
m %>>% (f %.% g)
is equal tom %>>% g %>>% f
.
Where above %.%
denotes function composition \(f, g) \(x) f(g(x))
.
References
https://wiki.haskell.org/Functor#Functor_Laws
See Also
Other implementation laws:
monad-laws
[Package monad version 0.1.1 Index]