-
Obtains the current value. Since
Refis always guaranteed to have a value, the returned action completes immetiately after being bound.Declaration
Swift
public func get() -> Kind<F, A>Return Value
A computation that provides the underlying value.
-
Sets the current value to a new value. The returned action completes after the reference has been successfully set.
Declaration
Swift
public func set(_ a: A) -> Kind<F, ()>Parameters
aNew value to be set.
Return Value
A computation that sets the underlying value.
-
Replaces the current value, returning the old value.
Declaration
Swift
public func getAndSet(_ a: A) -> Kind<F, A>Parameters
aNew value to be set.
Return Value
A computation that provides the old value saved in this reference.
-
Replaces the current value, returning the new value.
Declaration
Swift
public func setAndGet(_ a: A) -> Kind<F, A>Parameters
aNew value to be set.
Return Value
A computation that provides the new value saved in this reference.
-
Updates the current value with a function. If another modification occurs between the time the current value is read and subsequently updated, the modification is retried using the new value. Hence, the function may be invoked multiple times.
Declaration
Swift
public func update(_ f: @escaping (A) -> A) -> Kind<F, ()>Parameters
fTransforming function.
Return Value
A computation that updates the underlying value using the provided function.
-
Modifies the current value using the supplied update function and returns the old value.
Declaration
Swift
public func getAndUpdate(_ f: @escaping (A) -> A) -> Kind<F, A>Parameters
fTransforming function.
Return Value
A computation that provides the old value saved in this reference.
-
Modifies the current value using the supplied update function and returns the new value.
Declaration
Swift
public func updateAndGet(_ f: @escaping (A) -> A) -> Kind<F, A>Parameters
fTransforming function.
Return Value
A computation that provides the new value saved in this reference.
-
Updates the reference but allows the function to return an output of a different type.
Declaration
Swift
public func modify<B>(_ f: @escaping (A) -> (A, B)) -> Kind<F, B>Parameters
fTransforming function.
Return Value
A computation that updates the underlying value using the provided function.
-
Tries to modify the current value once, in contrast to update which calls the function until it succeeds.
Declaration
Swift
public func tryUpdate(_ f: @escaping (A) -> A) -> Kind<F, Bool>Parameters
fTransforming function.
Return Value
A computation that contains a flag indicating if the update was possible or not.
-
Tries to modify the current value once, in contrast to modify which calls the function until it succeeds.
Parameters
fTransforming function.
Return Value
A computation that provides an optional value with the result of the modification, if it happened.
-
Obtains a snapshot of the current value and a setter for updating it. The setter will return false if another concurrent call invalidated the snapshot; i.e. modified the value. It will return true if setting the value was successful. Once it has returned false or been used once, a setter never succeeds again.
Return Value
A computation providing a value and a setter.
-
Safely creates a
Ref.Declaration
Swift
static func of(_ f: @autoclosure @escaping () -> A) -> Kind<F, Ref<F, A>>Parameters
fFunction providing the initial value for the reference.
Return Value
A computation that provides the
Ref. -
Unsafely creates a
Ref.Declaration
Swift
static func unsafe(_ a: A) -> Ref<F, A>Parameters
aInitial value for the reference.
Return Value
A
Refcontaining the initial value.
Install in Dash
Ref Class Reference