servant/servant/src/Servant/API/Alternative.hs

42 lines
1.3 KiB
Haskell
Raw Normal View History

2015-04-20 19:52:29 +02:00
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
2015-09-28 18:17:22 +02:00
{-# LANGUAGE DeriveFoldable #-}
2018-03-11 16:58:31 +01:00
{-# LANGUAGE DeriveFunctor #-}
2015-09-28 18:06:49 +02:00
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeOperators #-}
2015-05-02 03:21:03 +02:00
{-# OPTIONS_HADDOCK not-home #-}
module Servant.API.Alternative ((:<|>)(..)) where
2018-03-11 16:58:31 +01:00
import Data.Semigroup
(Semigroup (..))
import Data.Typeable
(Typeable)
2016-03-01 19:25:04 +01:00
import Prelude ()
import Prelude.Compat
2016-03-01 12:21:21 +01:00
-- | Union of two APIs, first takes precedence in case of overlap.
2014-11-22 15:08:25 +01:00
--
-- Example:
--
-- >>> :{
--type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
-- :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books
-- :}
data a :<|> b = a :<|> b
2015-09-28 18:06:49 +02:00
deriving (Typeable, Eq, Show, Functor, Traversable, Foldable, Bounded)
infixr 3 :<|>
2017-01-19 18:04:36 +01:00
instance (Semigroup a, Semigroup b) => Semigroup (a :<|> b) where
(a :<|> b) <> (a' :<|> b') = (a <> a') :<|> (b <> b')
instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
mempty = mempty :<|> mempty
(a :<|> b) `mappend` (a' :<|> b') = (a `mappend` a') :<|> (b `mappend` b')
-- $setup
-- >>> import Servant.API
-- >>> import Data.Aeson
-- >>> import Data.Text
-- >>> data Book
-- >>> instance ToJSON Book where { toJSON = undefined }