Classes implementing fmap() are expected to satisfy two functor laws:
preservation of identity and preservation of composition.
Details
The Haskell functor laws can be translated into R as follows:
- Preservation of identity:
m %>>% identityis 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)).
See also
Other implementation laws:
monad-laws