graphql-engine/server/src-test/Control/Monad/MemoizeSpec.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
856 B
Haskell
Raw Normal View History

{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.MemoizeSpec (spec) where
import Control.Monad.MemoizationSpecDefinition
import Control.Monad.Memoize
import Hasura.Prelude
import Test.Hspec
-- We need to add a couple of extra parameters, 'k' and 'v', to align with the
-- shape of a memoizer as understood by 'Memoizer'.
newtype MemoizeWithExtraParamsT k v m a = MemoizeWithExtraParamsT {unMemoizeWithExtraParamsT :: MemoizeT m a}
deriving newtype (Functor, Applicative, Monad, MonadTrans)
instance Memoizer MemoizeWithExtraParamsT where
runMemoizer = runMemoizeT . unMemoizeWithExtraParamsT
memoize name key = MemoizeWithExtraParamsT . memoizeOn name key . unMemoizeWithExtraParamsT
deriving newtype instance MonadState s m => MonadState s (MemoizeWithExtraParamsT k v m)
spec :: Spec
spec = memoizationSpec @MemoizeWithExtraParamsT