git.iko.soy/typeable/servant
on master help sign in
Merge pull request #1032 from Taneb/master

Add bifunctors instances for Servant.API.Alt

commite066fbe493e11172e4f2836f33840c52ab4605ea authorOleg Grenrus <oleg.grenrus@iki.fi> dateFri 7 Sep 2018, 13:18 (8 years ago) parentb8f7eb443a1d58
2 files changed+23
servant/servant.cabal+1 servant/src/Servant/API/Alternative.hs+22
servant/servant.cabal+1
@@ -84,6 +84,7 @@ library
8484 -- Here can be exceptions if we really need features from the newer versions.
8585 build-depends:
8686 base-compat >= 0.10.4 && < 0.11
87+ , bifunctors >= 5.5.3 && < 5.6
8788 , aeson >= 1.3.1.1 && < 1.5
8889 , attoparsec >= 0.13.2.2 && < 0.14
8990 , case-insensitive >= 1.2.0.11 && < 1.3
servant/src/Servant/API/Alternative.hs+22
@@ -7,6 +7,15 @@
77{-# OPTIONS_HADDOCK not-home #-}
88module Servant.API.Alternative ((:<|>)(..)) where
99
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 (..))
1019import Data.Semigroup
1120 (Semigroup (..))
1221import Data.Typeable
@@ -33,6 +42,19 @@ instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
3342 mempty = mempty :<|> mempty
3443 (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
3544
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+
3658-- $setup
3759-- >>> import Servant.API
3860-- >>> import Data.Aeson