never executed always true always false
1 module ElmFormat.AST.PublicAST.MaybeF where
2
3
4 import Data.Coapplicative
5 data MaybeF f a
6 = JustF (f a)
7 | NothingF a
8 deriving (Functor)
9
10 instance Prelude.Foldable f => Prelude.Foldable (MaybeF f) where
11 foldMap f (JustF fa) = Prelude.foldMap f fa
12 foldMap f (NothingF a) = f a
13
14 instance Traversable f => Traversable (MaybeF f) where
15 traverse f (JustF fa) = JustF <$> traverse f fa
16 traverse f (NothingF a) = NothingF <$> f a
17
18 instance Coapplicative f => Coapplicative (MaybeF f) where
19 extract (JustF fa) = extract fa
20 extract (NothingF a) = a
21
22 maybeF :: (a -> x) -> (f a -> x) -> MaybeF f a -> x
23 maybeF fromA _ (NothingF a) = fromA a
24 maybeF _ fromFa (JustF fa) = fromFa fa