functor-laws: Functor Laws

functor-lawsR 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 to m |> identity().

Preservation of composition:

m %>>% (f %.% g) is equal to m %>>% 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


monad documentation built on Oct. 28, 2024, 5:07 p.m.