RefModule
PackageAxial
Summary
| Name | Signature | Synopsis |
|---|---|---|
| make | Ref.make value | Creates a new with the initial value. |
| get | Ref.get reference | Reads the current value of the reference. |
| set | Ref.set value reference | Sets the value of the reference to the specified value. |
| update | Ref.update f reference | Updates the value of the reference using the supplied function. |
| modify | Ref.modify f reference | Updates the value of the reference using the supplied function and returns a derived value. |
| getAndSet | Ref.getAndSet value reference | Sets the value of the reference and returns the value it held before the update. |
| getAndUpdate | Ref.getAndUpdate f reference | Updates the value using the supplied function and returns the value it held before the update. |
| updateAndGet | Ref.updateAndGet f reference | Updates the value using the supplied function and returns the value after the update. |
Creates a new Ref`1 with the initial value.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'T | The initial value of the reference. |
Returns
Flow<'env, 'none, Ref<'T>>
Verification Examples
(Ref.make 10).RunSynchronously(())Reads the current value of the reference.
Parameters
| Name | Type | Description |
|---|---|---|
| reference | Ref<'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
}Sets the value of the reference to the specified value.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'T | The new value to set. |
| reference | Ref<'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
}Updates the value of the reference using the supplied function.
Parameters
| Name | Type | Description |
|---|---|---|
| f | 'T -> 'T | The update function of type 'T -> 'T. |
| reference | Ref<'T> | The Ref`1 to update. |
Returns
Flow<'env, 'none, unit>
Verification Examples
Ref.update (fun x -> x + 1) myRefUpdates the value of the reference using the supplied function and returns a derived value.
Parameters
| Name | Type | Description |
|---|---|---|
| f | 'T -> 'v * 'T | The update function of type 'T -> 'v * 'T, returning the result before the next state. |
| reference | Ref<'T> | The Ref`1 to update. |
Returns
Flow<'env, 'none, 'v>
Verification Examples
Ref.modify (fun x -> "increased", x + 1) myRefSets the value of the reference and returns the value it held before the update.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'T | The new value to set. |
| reference | Ref<'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
}Updates the value using the supplied function and returns the value it held before the update.
Parameters
| Name | Type | Description |
|---|---|---|
| f | 'T -> 'T | The update function of type 'T -> 'T. |
| reference | Ref<'T> | The Ref`1 to update. |
Returns
Flow<'env, 'none, 'T>
Verification Examples
Ref.getAndUpdate (fun x -> x + 1) myRefUpdates the value using the supplied function and returns the value after the update.
Parameters
| Name | Type | Description |
|---|---|---|
| f | 'T -> 'T | The update function of type 'T -> 'T. |
| reference | Ref<'T> | The Ref`1 to update. |
Returns
Flow<'env, 'none, 'T>
Verification Examples
Ref.updateAndGet (fun x -> x + 1) myRef
