Module

Run.State.External

Package
purescript-run-external-state
Repository
Mateiadrielrafael/purescript-run-external-state

Alternative representation of State allowing for different interpreters

#ExternalState Source

data ExternalState s a

Alternative representation of State allowing for different interpreters

Constructors

#EXTERNAL_STATE Source

type EXTERNAL_STATE s r = (externalState :: ExternalState s | r)

#StateRunner Source

type StateRunner m s = { get :: m s, set :: s -> m Unit }

Pair of getter and setter functions for interpreting some external state

#get Source

get :: forall r s. Run (EXTERNAL_STATE s r) s

Get the current state

#put Source

put :: forall r s. s -> Run (EXTERNAL_STATE s r) Unit

Set the current state

#runExternalState Source

runExternalState :: forall s r. StateRunner (Run r) s -> (Run (EXTERNAL_STATE s r)) ~> (Run r)

Run some external state by using a pair of get and set functions

#runExternalStateEffectfully Source

runExternalStateEffectfully :: forall s r. StateRunner Effect s -> (Run ((EXTERNAL_STATE s) + (EFFECT r))) ~> (Run (EFFECT r))

Run the external state by calling some effects

#runExternalStateUsingRef Source

runExternalStateUsingRef :: forall s r. Ref s -> (Run ((EXTERNAL_STATE s) + (EFFECT r))) ~> (Run (EFFECT r))

Save the external state inside a ref

#imapExternaState Source

imapExternaState :: forall s a r. (s -> a) -> (a -> s) -> (Run ((EXTERNAL_STATE a) + (EXTERNAL_STATE s r))) ~> (Run (EXTERNAL_STATE s r))

External state is invariant over the state type parameter, so we can imap is.

#focusExternalState Source

focusExternalState :: forall s a r. Lens' s a -> (Run ((EXTERNAL_STATE a) + (EXTERNAL_STATE s r))) ~> (Run (EXTERNAL_STATE s r))

Run some state under the focus of a bigger state

#toInternalState Source

toInternalState :: forall r s a. Run ((EXTERNAL_STATE s) + (STATE s r)) a -> Run (STATE s r) a

Convert the external state to internal state

#runExternalStatePure Source

runExternalStatePure :: forall r s a. s -> Run ((EXTERNAL_STATE s) + (STATE s r)) a -> Run r (s /\ a)

Converts the state to internal state and then runs it purely

#gets Source

gets :: forall r a b. (a -> b) -> Run (EXTERNAL_STATE a r) b

Get the current state and run a function over it

#modify Source

modify :: forall r s. (s -> s) -> Run (EXTERNAL_STATE s r) s

Run a function over the current state

#modify_ Source

modify_ :: forall r s. (s -> s) -> Run (EXTERNAL_STATE s r) Unit

Run a function over the current state, discarding the result

#modifying Source

modifying :: forall s a b r. Setter s s a b -> (a -> b) -> Run (EXTERNAL_STATE s r) Unit

Run a function by focusing on the state using an optic

#assign Source

assign :: forall s a b r. Setter s s a b -> b -> Run (EXTERNAL_STATE s r) Unit

Set the value of a focus on the state

#use Source

use :: forall s t a b r. Getter s t a b -> Run (EXTERNAL_STATE s r) a

Get the value of a focus on the state

#preuse Source

preuse :: forall s t a b r. Fold (First a) s t a b -> Run (EXTERNAL_STATE s r) (Maybe a)

Attempt getting the value of a focus on the state

#_externalState Source

_externalState :: Proxy "externalState"