module Hedgehog.Extras.Stock.CallStack
  ( callerModuleName
  ) where

import           Data.Function
import           Data.Maybe
import           Data.String
import           Data.Tuple
import           GHC.Stack (HasCallStack, callStack, getCallStack, srcLocModule)

-- | Get the module name of the caller.
callerModuleName :: HasCallStack => String
callerModuleName :: HasCallStack => String
callerModuleName = String
-> ((String, SrcLoc) -> String) -> Maybe (String, SrcLoc) -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"<no-module>" (SrcLoc -> String
srcLocModule (SrcLoc -> String)
-> ((String, SrcLoc) -> SrcLoc) -> (String, SrcLoc) -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, SrcLoc) -> SrcLoc
forall a b. (a, b) -> b
snd) ([(String, SrcLoc)] -> Maybe (String, SrcLoc)
forall a. [a] -> Maybe a
listToMaybe (CallStack -> [(String, SrcLoc)]
getCallStack CallStack
HasCallStack => CallStack
callStack))