-
Initializes an atomic value with an initial value.
Declaration
Swift
public init(_ value: A)
Parameters
value
Initial value for this reference.
-
Gets or sets the underlying value in a thread-safe manner.
Declaration
Swift
public var value: A { get set }
-
Mutates the underlying value using the provided function.
Declaration
Swift
public func mutate(_ transform: (inout A) -> ())
Parameters
transform
Transformation function
-
Gets the underlying value and sets a new value.
Declaration
Swift
public func getAndSet(_ newValue: A) -> A
Parameters
newValue
New value to be stored in this atomic reference.
Return Value
Previous value saved in this reference, before the modification.
-
Gets the underlying value and sets a new value transforming it with a function.
Declaration
Swift
public func getAndUpdate(_ f: @escaping (A) -> A) -> A
Parameters
f
Transforming function.
Return Value
Previous value saved in this reference, before the modification.
-
Sets a new value in this atomic reference and gets the newly updated value.
Declaration
Swift
public func setAndGet(_ newValue: A) -> A
Parameters
newValue
Value to be set in this atomic reference.
Return Value
Newly set value.
-
Sets a new value transforming the underlying one using a function and gets the new value.
Declaration
Swift
public func updateAndGet(_ f: @escaping (A) -> A) -> A
Parameters
f
Transforming value.
Return Value
Value resulting from transforming the underlying value.
-
Sets a new value if the underlying value is nil
Declaration
Swift
@discardableResult public func setIfNil<AA>(_ newValue: AA) -> Bool where A == AA?
Parameters
newValue
Value to be set.
Return Value
True if the new value was set; false, otherwise.
-
Sets the underlying value to nil
Declaration
Swift
public func setNil<AA>() where A == AA?
-
Sets a new value if the underlying value is equal to the one passed as a test.
Declaration
Swift
public func compare(_ test: A, andSet newValue: A) -> Bool
Parameters
test
Value to compare with the underlying value.
newValue
Value to be set.
Return Value
True if the new value was set; false, otherwise.