-- | Extras for working with servant
module Hercules.API.Servant where

import Control.Monad (void)
import Servant.API
import Servant.API.Generic
import Prelude

-- | Postcomposes 'Servant.API.Generic.fromServant' to an accessor,
-- preserving the mode parameter, because otherwise the mode parameter
-- can not be inferred.
--
-- Ideally, this functionality would be built into a new combinator.
useApi ::
  (GenericServant f mode, GenericServant g mode) =>
  (f mode -> ToServant g mode) ->
  f mode ->
  g mode
useApi :: (f mode -> ToServant g mode) -> f mode -> g mode
useApi = (ToServant g mode -> g mode
forall (routes :: * -> *) mode.
GenericServant routes mode =>
ToServant routes mode -> routes mode
Servant.API.Generic.fromServant (ToServant g mode -> g mode)
-> (f mode -> ToServant g mode) -> f mode -> g mode
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)

-- | 'Control.Monad.void' specialised to 'NoContent' to soothe the
-- compiler that rightfully warns about throwing away a do notation
-- result. By specialising, we make sure that we still get warnings
-- if the result type changes in the future. (We'll get an error)
noContent :: Functor m => m Servant.API.NoContent -> m ()
noContent :: m NoContent -> m ()
noContent = m NoContent -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void