Skip to content

Identity

The identity functor is an even simpler container than Maybe. It always contains exactly one element. Thus, foldl should return the result of combining this element with the initial accumulator value:

instance Foldable Identity where
    foldl f init (Identity x) = f init x

foldMap always returns simply f x for the element x stored in the container:

instance Foldable Identity where
    foldMap f (Identity x) = f x