RefModule

PackageAxial

Summary

NameSignatureSynopsis
makeRef.make valueCreates a new with the initial value.
getRef.get referenceReads the current value of the reference.
setRef.set value referenceSets the value of the reference to the specified value.
updateRef.update f referenceUpdates the value of the reference using the supplied function.
modifyRef.modify f referenceUpdates the value of the reference using the supplied function and returns a derived value.
getAndSetRef.getAndSet value referenceSets the value of the reference and returns the value it held before the update.
getAndUpdateRef.getAndUpdate f referenceUpdates the value using the supplied function and returns the value it held before the update.
updateAndGetRef.updateAndGet f referenceUpdates the value using the supplied function and returns the value after the update.

make

Ref.make value
Member
Creates a new Ref`1 with the initial value.

Parameters

NameTypeDescription
value'TThe initial value of the reference.

Returns

Flow<'env, 'none, Ref<'T>>

Verification Examples

(Ref.make 10).RunSynchronously(())

get

Ref.get reference
Member
Reads the current value of the reference.

Parameters

NameTypeDescription
referenceRef<'T>The Ref`1 to read from.

Returns

Flow<'env, 'none, 'T>

Verification Examples

let readInitialValue () =
    flow {
        let! reference = Ref.make 10
        return! Ref.get reference
    }

set

Ref.set value reference
Member
Sets the value of the reference to the specified value.

Parameters

NameTypeDescription
value'TThe new value to set.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, unit>

Verification Examples

let replaceValue () =
    flow {
        let! reference = Ref.make 10
        do! Ref.set 20 reference
    }

update

Ref.update f reference
Member
Updates the value of the reference using the supplied function.

Parameters

NameTypeDescription
f'T -> 'TThe update function of type 'T -> 'T.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, unit>

Verification Examples

Ref.update (fun x -> x + 1) myRef

modify

Ref.modify f reference
Member
Updates the value of the reference using the supplied function and returns a derived value.

Parameters

NameTypeDescription
f'T -> 'v * 'TThe update function of type 'T -> 'v * 'T, returning the result before the next state.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, 'v>

Verification Examples

Ref.modify (fun x -> "increased", x + 1) myRef

getAndSet

Ref.getAndSet value reference
Member
Sets the value of the reference and returns the value it held before the update.

Parameters

NameTypeDescription
value'TThe new value to set.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, 'T>

Verification Examples

let replaceAndReturnPrevious () =
    flow {
        let! reference = Ref.make 10
        return! Ref.getAndSet 20 reference
    }

getAndUpdate

Ref.getAndUpdate f reference
Member
Updates the value using the supplied function and returns the value it held before the update.

Parameters

NameTypeDescription
f'T -> 'TThe update function of type 'T -> 'T.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, 'T>

Verification Examples

Ref.getAndUpdate (fun x -> x + 1) myRef

updateAndGet

Ref.updateAndGet f reference
Member
Updates the value using the supplied function and returns the value after the update.

Parameters

NameTypeDescription
f'T -> 'TThe update function of type 'T -> 'T.
referenceRef<'T>The Ref`1 to update.

Returns

Flow<'env, 'none, 'T>

Verification Examples

Ref.updateAndGet (fun x -> x + 1) myRef