ribosome-host-0.9.9.9: Neovim plugin host for Polysemy
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ribosome.Host.Effect.MState

Description

A state effect that allows atomic updates with monadic actions.

Synopsis

Documentation

data MState s :: Effect where Source #

A state effect that allows atomic updates with monadic actions.

The constructor muse is analogous to the usual state combinator, in that it transforms the state monadically alongside a return value, but unlike State and AtomicState, the callback may be a Sem.

This is accomplished by locking every call with an MVar.

For read-only access to the state that doesn't care about currently running updates, the constructor mread directly returns the state without consulting the lock.

Constructors

Use :: (s -> m (s, a)) -> MState s m a

Run a monadic action on the state in a mutually exclusive fashion that additionally returns a value.

Read :: MState s m s

Obtain the current state.

muse :: Member (MState s) r => (s -> Sem r (s, a)) -> Sem r a Source #

Run a monadic action on the state in a mutually exclusive fashion that additionally returns a value.

mtrans :: Member (MState s) r => (s -> Sem r s) -> Sem r () Source #

Run a monadic action on the state in a mutually exclusive fashion.

mstate :: Member (MState s) r => (s -> (s, a)) -> Sem r a Source #

Apply a pure function to the state that additionally returns a value.

mmodify :: Member (MState s) r => (s -> s) -> Sem r () Source #

Apply a pure function to the state.

mput :: Member (MState s) r => s -> Sem r () Source #

Replace the state.

mread :: Member (MState s) r => Sem r s Source #

Obtain the current state.

mreads :: Member (MState s) r => (s -> a) -> Sem r a Source #

Obtain the current state, transformed by a pure function.

stateToMState :: Member (MState s) r => InterpreterFor (State s) r Source #

Interpret State in terms of MState.

type ScopedMState s = PScoped s () (MState s) Source #

A PScoped alias for MState that allows running it on a local region without having to involve IO in the stack.

withMState :: Member (ScopedMState s) r => s -> InterpreterFor (MState s) r Source #

Run a PScoped MState on a local region without having to involve IO in the stack.