File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
servant-server/src/Servant Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change
1
+ synopsis: Add `MkHandler` pattern synonym
2
+ prs: #1733
3
+ issues: #1732
4
+ description: {
5
+ Add a bidirectional pattern synonym to construct `Handler a` values from `IO
6
+ (Either ServerError a)` ones, and match in the other direction.
7
+ }
Original file line number Diff line number Diff line change 5
5
{-# LANGUAGE ScopedTypeVariables #-}
6
6
{-# LANGUAGE TypeFamilies #-}
7
7
{-# LANGUAGE TypeOperators #-}
8
+ {-# LANGUAGE PatternSynonyms #-}
8
9
9
10
-- | This module lets you implement 'Server's for defined APIs. You'll
10
11
-- most likely just need 'serve'.
@@ -25,6 +26,7 @@ module Servant.Server
25
26
, emptyServer
26
27
, Handler (.. )
27
28
, runHandler
29
+ , pattern MkHandler
28
30
29
31
-- * Debugging the server layout
30
32
, layout
Original file line number Diff line number Diff line change 3
3
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4
4
{-# LANGUAGE MultiParamTypeClasses #-}
5
5
{-# LANGUAGE TypeFamilies #-}
6
+ {-# LANGUAGE PatternSynonyms #-}
6
7
module Servant.Server.Internal.Handler where
7
8
8
9
import Prelude ()
@@ -19,7 +20,7 @@ import Control.Monad.IO.Class
19
20
import Control.Monad.Trans.Control
20
21
(MonadBaseControl (.. ))
21
22
import Control.Monad.Trans.Except
22
- (ExceptT , runExceptT )
23
+ (ExceptT ( ExceptT ) , runExceptT )
23
24
import Data.String
24
25
(fromString )
25
26
import GHC.Generics
@@ -51,3 +52,10 @@ instance MonadBaseControl IO Handler where
51
52
52
53
runHandler :: Handler a -> IO (Either ServerError a )
53
54
runHandler = runExceptT . runHandler'
55
+
56
+ -- | Pattern synonym that matches directly on the inner 'IO' action.
57
+ --
58
+ -- To lift 'IO' actions that don't carry a 'ServerError', use 'Control.Monad.IO.Class.liftIO' instead.
59
+ pattern MkHandler :: IO (Either ServerError a ) -> Handler a
60
+ pattern MkHandler ioe = Handler (ExceptT ioe)
61
+ {-# COMPLETE MkHandler #-}
You can’t perform that action at this time.
0 commit comments