module Data.Registry.Internal.Stack where
import Data.Registry.Internal.Statistics
import Data.Registry.Internal.Types
import Protolude
type Stack a = StateT Statistics (Either Text) a
runStack :: Stack a -> Either Text a
runStack = runStackWithValues mempty
runStackWithValues :: Values -> Stack a -> Either Text a
runStackWithValues vs sa = evalStateT sa (initStatistics vs)
execStack :: Stack a -> Either Text Values
execStack = execStackWithValues mempty
execStackWithValues :: Values -> Stack a -> Either Text Values
execStackWithValues vs sa = values <$> execStateT sa (initStatistics vs)
evalStack :: Stack a -> Either Text Statistics
evalStack = evalStackWithValues mempty
evalStackWithValues :: Values -> Stack a -> Either Text Statistics
evalStackWithValues vs sa = execStateT sa (initStatistics vs)
getValues :: Stack Values
getValues = values <$> get
getOperations :: Stack Operations
getOperations = operations <$> get
modifyValues :: (Values -> Values) -> Stack ()
modifyValues f = modifyStatistics (\s -> s { values = f (values s) })
modifyOperations :: (Operations -> Operations) -> Stack ()
modifyOperations f = modifyStatistics (\s -> s { operations = f (operations s) })
modifyStatistics :: (Statistics -> Statistics) -> Stack ()
modifyStatistics = modify
functionApplied :: Value -> [Value] -> Stack ()
functionApplied output inputs = modifyOperations (AppliedFunction output inputs:)