{-# language NoImplicitPrelude #-}
{-# options_haddock prune #-}

-- | Combinators related to 'TestError'.
module Zeugma.TestError where

import Incipit
import Polysemy.Test (TestError (TestError))

-- | Interpret 'Stop' by throwing a 'TestError', with the call site's stack.
stopTest ::
   err r .
  Show err =>
  HasCallStack =>
  Member (Error TestError) r =>
  InterpreterFor (Stop err) r
stopTest :: forall err (r :: EffectRow).
(Show err, HasCallStack, Member (Error TestError) r) =>
InterpreterFor (Stop err) r
stopTest Sem (Stop err : r) a
ma =
  forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack (forall err err' (r :: EffectRow) a.
Member (Error err') r =>
(err -> err') -> Sem (Stop err : r) a -> Sem r a
stopToErrorWith (Text -> TestError
TestError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. (Show a, IsString b) => a -> b
show) Sem (Stop err : r) a
ma)

-- | Interpret an effect into 'Resumable' by throwing a 'TestError' for 'Stop's, with the call site's stack.
resumeTest ::
   err eff r .
  Show err =>
  HasCallStack =>
  Members [eff !! err, Error TestError] r =>
  InterpreterFor eff r
resumeTest :: forall err (eff :: Effect) (r :: EffectRow).
(Show err, HasCallStack,
 Members '[eff !! err, Error TestError] r) =>
InterpreterFor eff r
resumeTest Sem (eff : r) a
ma =
  forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack (forall err (eff :: Effect) err' (r :: EffectRow) a.
Members '[Resumable err eff, Error err'] r =>
(err -> err') -> Sem (eff : r) a -> Sem r a
resumeHoistError @err (Text -> TestError
TestError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. (Show a, IsString b) => a -> b
show) Sem (eff : r) a
ma)