3.2.4. effect.ref module

class effect.ref.ModifyReference(ref, transformer)

Bases: object

Intent that modifies a Reference value in-place with a transformer func.

This intent is not necessarily linearizable if multiple threads are modifying the same reference at the same time.

ref = Attribute(name='ref', default=NOTHING, validator=None, repr=True, cmp=True, hash=True, init=True)
transformer = Attribute(name='transformer', default=NOTHING, validator=None, repr=True, cmp=True, hash=True, init=True)
class effect.ref.ReadReference(ref)

Bases: object

Intent that gets a Reference’s current value.

ref = Attribute(name='ref', default=NOTHING, validator=None, repr=True, cmp=True, hash=True, init=True)
class effect.ref.Reference(initial)

Bases: object

An effectful mutable variable, suitable for sharing between multiple logical threads of execution, that can be read and modified in a purely functional way.

Compare to Haskell’s IORef or Clojure’s atom.

modify(transformer)

Return an Effect that updates the value with fn(old_value).

Parameters:transformer – Function that takes old value and returns the new value.

This is not guaranteed to be linearizable if multiple threads are modifying the reference at the same time. It is safe to assume consistent modification as long as you’re not using multiple threads, though.

read()

Return an Effect that results in the current value.

effect.ref.perform_modify_reference(*args)

Performer for ModifyReference.

This performer is not linearizable if multiple physical threads are modifying the same reference at the same time.

effect.ref.perform_read_reference(*args)

Performer for ReadReference.