Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bifunctor instance for ReqResult #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Servant/Common/Req.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Control.Arrow ((&&&))
import Control.Concurrent
import Control.Monad (join)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Bifunctor (first)
import Data.Bifunctor (Bifunctor(..))
import qualified Data.ByteString.Builder as Builder
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.ByteString (ByteString)
Expand Down Expand Up @@ -52,6 +52,13 @@ data ReqResult tag a
-- ^ A failure to construct the request tagged with 'tag' at trigger time
deriving (Functor)

instance Bifunctor ReqResult where
first f = \case
ResponseSuccess tag a r -> ResponseSuccess (f tag) a r
ResponseFailure tag t r -> ResponseFailure (f tag) t r
RequestFailure tag t -> RequestFailure (f tag) t
second = fmap

data ClientOptions = ClientOptions
{ optsRequestFixup :: forall a. Show a => XhrRequest a -> JSM (XhrRequest a)
-- ^ Aribtrarily modify requests just before they are sent.
Expand Down