This module allows the creation of mutable behaviors. That is, behaviors whose value can be changed in an Effect.

This module intentionally resembles Effect.Ref. The only difference in the API is the presence of toBehavior and new' which makes it possible to extract a Behavior from a BehaviorRef.

#BehaviorRef Source

data BehaviorRef :: Type -> Type

A BehaviorRef represents a behavior whose current value can be mutated similarly to a Ref.

#new Source

new :: forall a. a -> Effect (BehaviorRef a)

An effectful computation that creates a BehaviorRef. A BehaviorRef is a behavior that one can imperatively change the value of by using the writerBehavior function.

#new' Source

new' :: forall a. a -> Effect { behavior :: Behavior a, ref :: BehaviorRef a }

This is convenience function for the common use-case of calling new and then also converting the BehaviorRef into a Behavior with toBehavior.

The code

ref <- new 0
behavior <- toBehavior ref

Is equivalent to

{ ref, behavior } <- new'

#toBehavior Source

toBehavior :: BehaviorRef ~> Behavior

Extracts the Behavior from a BehaviorRef.

#read Source

read :: forall a. BehaviorRef a -> Effect a

Reads the current value of a BehaviorRef.

#modify' Source

modify' :: forall a b. (a -> { state :: a, value :: b }) -> BehaviorRef a -> Effect b

#modify Source

modify :: forall s. (s -> s) -> BehaviorRef s -> Effect s

#modify_ Source

modify_ :: forall s. (s -> s) -> BehaviorRef s -> Effect Unit

#write Source

write :: forall a. a -> BehaviorRef a -> Effect Unit

Change the value of the BehaviorRef into the given value.