on master help sign in
Merge pull request #1032 from Taneb/master
e066fbeOleg Grenrus
servant/servant.cabal+1
@@ -84,6 +84,7 @@ library
84 -- Here can be exceptions if we really need features from the newer versions.
84 -- Here can be exceptions if we really need features from the newer versions.
85 build-depends:
85 build-depends:
86 base-compat >= 0.10.4 && < 0.11
86 base-compat >= 0.10.4 && < 0.11
87+ , bifunctors >= 5.5.3 && < 5.6
87 , aeson >= 1.3.1.1 && < 1.5
88 , aeson >= 1.3.1.1 && < 1.5
88 , attoparsec >= 0.13.2.2 && < 0.14
89 , attoparsec >= 0.13.2.2 && < 0.14
89 , case-insensitive >= 1.2.0.11 && < 1.3
90 , case-insensitive >= 1.2.0.11 && < 1.3
servant/src/Servant/API/Alternative.hs+22
@@ -7,6 +7,15 @@
7{-# OPTIONS_HADDOCK not-home #-}
7{-# OPTIONS_HADDOCK not-home #-}
8module Servant.API.Alternative ((:<|>)(..)) where
8module Servant.API.Alternative ((:<|>)(..)) where
9
9
10+import Control.Applicative (liftA2)
11+import Data.Biapplicative
12+ (Biapplicative (..))
13+import Data.Bifoldable
14+ (Bifoldable (..))
15+import Data.Bifunctor
16+ (Bifunctor (..))
17+import Data.Bitraversable
18+ (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')
35
44
45+instance Bifoldable (:<|>) where
46+ bifoldMap f g ~(a :<|> b) = f a `mappend` g b
47+
48+instance Bifunctor (:<|>) where
49+ bimap f g ~(a :<|> b) = f a :<|> g b
50+
51+instance Biapplicative (:<|>) where
52+ bipure = (:<|>)
53+ (f :<|> g) <<*>> (a :<|> b) = f a :<|> g b
54+
55+instance Bitraversable (:<|>) where
56+ bitraverse f g ~(a :<|> b) = liftA2 (:<|>) (f a) (g b)
57+
36-- $setup
58-- $setup
37-- >>> import Servant.API
59-- >>> import Servant.API
38-- >>> import Data.Aeson
60-- >>> import Data.Aeson