@@ -7,6 +7,15 @@
7{-# OPTIONS_HADDOCK not-home #-}
7{-# OPTIONS_HADDOCK not-home #-}
8module Servant.API.Alternative ((:<|>)(..)) where
8module Servant.API.Alternative ((:<|>)(..)) where
10+import Control.Applicative (liftA2)
11+import Data.Biapplicative
13+import Data.Bifoldable
17+import Data.Bitraversable
10import Data.Semigroup
19import Data.Semigroup
11 (Semigroup (..))
20 (Semigroup (..))
12import Data.Typeable
21import Data.Typeable
@@ -33,6 +42,19 @@ instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
33 mempty = mempty :<|> mempty
42 mempty = mempty :<|> mempty
34 (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
43 (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
45+instance Bifoldable (:<|>) where
46+ bifoldMap f g ~(a :<|> b) = f a `mappend` g b
48+instance Bifunctor (:<|>) where
49+ bimap f g ~(a :<|> b) = f a :<|> g b
51+instance Biapplicative (:<|>) where
53+ (f :<|> g) <<*>> (a :<|> b) = f a :<|> g b
55+instance Bitraversable (:<|>) where
56+ bitraverse f g ~(a :<|> b) = liftA2 (:<|>) (f a) (g b)
37-- >>> import Servant.API
59-- >>> import Servant.API
38-- >>> import Data.Aeson
60-- >>> import Data.Aeson