Update and publish catamorphism article

This commit is contained in:
2022-04-24 01:09:34 -07:00
parent ded50480a8
commit 57aecc46be
2 changed files with 49 additions and 1 deletions

View File

@@ -99,3 +99,14 @@ invert :: BinaryTree a -> BinaryTree a
invert = cata $ \case
LeafF -> Leaf
NodeF a l r -> Node a r l
data MaybeF a b = NothingF | JustF a deriving Functor
instance Cata (Maybe a) (MaybeF a) where
out Nothing = NothingF
out (Just x) = JustF x
getOrDefault :: a -> Maybe a -> a
getOrDefault d = cata $ \case
NothingF -> d
JustF a -> a