on master help sign in
Merge pull request #679 from phadej/semigroup
25110feOleg Grenrus
servant-client/servant-client.cabal+4
@@ -52,6 +52,7 @@ library
52 , monad-control >= 1.0.0.4 && < 1.1
52 , monad-control >= 1.0.0.4 && < 1.1
53 , network-uri >= 2.6 && < 2.7
53 , network-uri >= 2.6 && < 2.7
54 , safe >= 0.3.9 && < 0.4
54 , safe >= 0.3.9 && < 0.4
55+ , semigroupoids >= 4.3 && < 5.2
55 , servant == 0.9.*
56 , servant == 0.9.*
56 , string-conversions >= 0.3 && < 0.5
57 , string-conversions >= 0.3 && < 0.5
57 , text >= 1.2 && < 1.3
58 , text >= 1.2 && < 1.3
@@ -59,6 +60,9 @@ library
59 , transformers-base >= 0.4.4 && < 0.5
60 , transformers-base >= 0.4.4 && < 0.5
60 , transformers-compat >= 0.4 && < 0.6
61 , transformers-compat >= 0.4 && < 0.6
61 , mtl
62 , mtl
63+ if !impl(ghc >= 8.0)
64+ build-depends:
65+ semigroups >=0.16.2.2 && <0.19
62 hs-source-dirs: src
66 hs-source-dirs: src
63 default-language: Haskell2010
67 default-language: Haskell2010
64 ghc-options: -Wall
68 ghc-options: -Wall
servant-client/src/Servant/Common/Req.hs+7−1
@@ -16,6 +16,8 @@ import Control.Exception
16import Control.Monad
16import Control.Monad
17import Control.Monad.Catch (MonadThrow, MonadCatch)
17import Control.Monad.Catch (MonadThrow, MonadCatch)
18import Data.Foldable (toList)
18import Data.Foldable (toList)
19+import Data.Functor.Alt (Alt (..))
20+import Data.Semigroup ((<>))
19
21
20import Control.Monad.Error.Class (MonadError(..))
22import Control.Monad.Error.Class (MonadError(..))
21import Control.Monad.Trans.Except
23import Control.Monad.Trans.Except
@@ -27,7 +29,7 @@ import Control.Monad.Reader
27import Control.Monad.Trans.Control (MonadBaseControl (..))
29import Control.Monad.Trans.Control (MonadBaseControl (..))
28import Data.ByteString.Lazy hiding (pack, filter, map, null, elem, any)
30import Data.ByteString.Lazy hiding (pack, filter, map, null, elem, any)
29import Data.String
31import Data.String
30−import Data.String.Conversions
32+import Data.String.Conversions (cs)
31import Data.Proxy
33import Data.Proxy
32import Data.Text (Text)
34import Data.Text (Text)
33import Data.Text.Encoding
35import Data.Text.Encoding
@@ -214,6 +216,10 @@ instance MonadBaseControl IO ClientM where
214 -- restoreM :: StM ClientM a -> ClientM a
216 -- restoreM :: StM ClientM a -> ClientM a
215 restoreM st = ClientM (restoreM st)
217 restoreM st = ClientM (restoreM st)
216
218
219+-- | Try clients in order, last error is preserved.
220+instance Alt ClientM where
221+ a <!> b = a `catchError` \_ -> b
222+
217runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a)
223runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a)
218runClientM cm env = runExceptT $ (flip runReaderT env) $ runClientM' cm
224runClientM cm env = runExceptT $ (flip runReaderT env) $ runClientM' cm
219
225
servant-docs/servant-docs.cabal+4
@@ -33,6 +33,7 @@ library
33 , Servant.Docs.Internal.Pretty
33 , Servant.Docs.Internal.Pretty
34 build-depends:
34 build-depends:
35 base >=4.7 && <5
35 base >=4.7 && <5
36+ , base-compat >= 0.9.1 && <0.10
36 , aeson
37 , aeson
37 , aeson-pretty
38 , aeson-pretty
38 , bytestring
39 , bytestring
@@ -46,6 +47,9 @@ library
46 , text
47 , text
47 , unordered-containers
48 , unordered-containers
48 , control-monad-omega == 0.3.*
49 , control-monad-omega == 0.3.*
50+ if !impl(ghc >= 8.0)
51+ build-depends:
52+ semigroups >=0.16.2.2 && <0.19
49 hs-source-dirs: src
53 hs-source-dirs: src
50 default-language: Haskell2010
54 default-language: Haskell2010
51 ghc-options: -Wall
55 ghc-options: -Wall
servant-docs/src/Servant/Docs/Internal.hs+11−3
@@ -20,6 +20,8 @@
20#include "overlapping-compat.h"
20#include "overlapping-compat.h"
21module Servant.Docs.Internal where
21module Servant.Docs.Internal where
22
22
23+import Prelude ()
24+import Prelude.Compat
23import Control.Applicative
25import Control.Applicative
24import Control.Arrow (second)
26import Control.Arrow (second)
25import Control.Lens (makeLenses, mapped, over, traversed, view, (%~),
27import Control.Lens (makeLenses, mapped, over, traversed, view, (%~),
@@ -30,9 +32,10 @@ import qualified Data.ByteString.Char8 as BSC
30import qualified Data.CaseInsensitive as CI
32import qualified Data.CaseInsensitive as CI
31import Data.Hashable (Hashable)
33import Data.Hashable (Hashable)
32import Data.HashMap.Strict (HashMap)
34import Data.HashMap.Strict (HashMap)
33−import Data.List
35+import Data.List.Compat (intercalate, intersperse, sort)
34import Data.Maybe
36import Data.Maybe
35−import Data.Monoid
37+import Data.Monoid (All (..), Any (..), Sum (..), Product (..), First (..), Last (..), Dual (..))
38+import Data.Semigroup (Semigroup (..))
36import Data.Ord (comparing)
39import Data.Ord (comparing)
37import Data.Proxy (Proxy(Proxy))
40import Data.Proxy (Proxy(Proxy))
38import Data.String.Conversions (cs)
41import Data.String.Conversions (cs)
@@ -102,8 +105,11 @@ data API = API
102 , _apiEndpoints :: HashMap Endpoint Action
105 , _apiEndpoints :: HashMap Endpoint Action
103 } deriving (Eq, Show)
106 } deriving (Eq, Show)
104
107
108+instance Semigroup API where
109+ (<>) = mappend
110+
105instance Monoid API where
111instance Monoid API where
106− API a1 b1 `mappend` API a2 b2 = API (a1 <> a2) (b1 <> b2)
112+ API a1 b1 `mappend` API a2 b2 = API (a1 `mappend` a2) (b1 `mappend` b2)
107 mempty = API mempty mempty
113 mempty = API mempty mempty
108
114
109-- | An empty 'API'
115-- | An empty 'API'
@@ -162,6 +168,8 @@ data DocNote = DocNote
162-- These are intended to be built using extraInfo.
168-- These are intended to be built using extraInfo.
163-- Multiple ExtraInfo may be combined with the monoid instance.
169-- Multiple ExtraInfo may be combined with the monoid instance.
164newtype ExtraInfo api = ExtraInfo (HashMap Endpoint Action)
170newtype ExtraInfo api = ExtraInfo (HashMap Endpoint Action)
171+instance Semigroup (ExtraInfo a) where
172+ (<>) = mappend
165instance Monoid (ExtraInfo a) where
173instance Monoid (ExtraInfo a) where
166 mempty = ExtraInfo mempty
174 mempty = ExtraInfo mempty
167 ExtraInfo a `mappend` ExtraInfo b =
175 ExtraInfo a `mappend` ExtraInfo b =
servant/src/Servant/API/Alternative.hs+4
@@ -7,6 +7,7 @@
7{-# OPTIONS_HADDOCK not-home #-}
7{-# OPTIONS_HADDOCK not-home #-}
8module Servant.API.Alternative ((:<|>)(..)) where
8module Servant.API.Alternative ((:<|>)(..)) where
9
9
10+import Data.Semigroup (Semigroup (..))
10import Data.Typeable (Typeable)
11import Data.Typeable (Typeable)
11import Prelude ()
12import Prelude ()
12import Prelude.Compat
13import Prelude.Compat
@@ -23,6 +24,9 @@ data a :<|> b = a :<|> b
23 deriving (Typeable, Eq, Show, Functor, Traversable, Foldable, Bounded)
24 deriving (Typeable, Eq, Show, Functor, Traversable, Foldable, Bounded)
24infixr 8 :<|>
25infixr 8 :<|>
25
26
27+instance (Semigroup a, Semigroup b) => Semigroup (a :<|> b) where
28+ (a :<|> b) <> (a' :<|> b') = (a <> a') :<|> (b <> b')
29+
26instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
30instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
27 mempty = mempty :<|> mempty
31 mempty = mempty :<|> mempty
28 (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
32 (a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
servant/src/Servant/Utils/Links.hs+1−1
@@ -82,7 +82,7 @@ module Servant.Utils.Links (
82
82
83 -- * Building and using safe links
83 -- * Building and using safe links
84 --
84 --
85− -- | Note that 'URI' is Network.URI.URI from the network-uri package.
85+ -- | Note that 'URI' is from the "Network.URI" module in the @network-uri@ package.
86 safeLink
86 safeLink
87 , URI(..)
87 , URI(..)
88 -- * Adding custom types
88 -- * Adding custom types