Update and publish catamorphism article
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user