diff --git a/Sources/CRDT/CvRDT.swift b/Sources/CRDT/CvRDT.swift index b139144..ffb14db 100644 --- a/Sources/CRDT/CvRDT.swift +++ b/Sources/CRDT/CvRDT.swift @@ -22,13 +22,4 @@ public protocol CvRDT: PartialOrderable { /// - Parameter other: The other instance /// - Throws: Throws an error if the states could not be merged. mutating func merge(_ other: Self) throws - - /// An idempotent and commutative function which attempts to produce a new instance with the - /// other instance's state merged with this instance's state. - /// - /// - Parameter other: The other instance - /// - Throws: Throws an error if the states could not be merged. - /// - Returns: A new instance which is the result of merging this instance's state with the - /// other instance's state. - func merged(_ other: Self) throws -> Self } diff --git a/Sources/CRDT/VClock.swift b/Sources/CRDT/VClock.swift index 267f47f..b288342 100644 --- a/Sources/CRDT/VClock.swift +++ b/Sources/CRDT/VClock.swift @@ -271,6 +271,13 @@ extension VClock: CvRDT { } } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: VClock) throws -> VClock { var copy = self try copy.merge(other) diff --git a/Sources/CRDTCounters/GCounter.swift b/Sources/CRDTCounters/GCounter.swift index d288e02..9c480ed 100644 --- a/Sources/CRDTCounters/GCounter.swift +++ b/Sources/CRDTCounters/GCounter.swift @@ -77,6 +77,13 @@ extension GCounter: CvRDT { try self.actorCounters.merge(other.actorCounters) } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: GCounter) throws -> GCounter { var copy = self try copy.merge(other) diff --git a/Sources/CRDTRegisters/LWWRegister.swift b/Sources/CRDTRegisters/LWWRegister.swift index cb203b5..878105d 100644 --- a/Sources/CRDTRegisters/LWWRegister.swift +++ b/Sources/CRDTRegisters/LWWRegister.swift @@ -77,6 +77,13 @@ extension LWWRegister: CvRDT { try self.assign(value: other.value, timestamp: other.timestamp) } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: LWWRegister) throws -> LWWRegister { var copy = self try copy.merge(other) diff --git a/Sources/CRDTRegisters/MVRegister.swift b/Sources/CRDTRegisters/MVRegister.swift index 5279837..5662bb2 100644 --- a/Sources/CRDTRegisters/MVRegister.swift +++ b/Sources/CRDTRegisters/MVRegister.swift @@ -195,6 +195,13 @@ extension MVRegister: CvRDT { self.values = keptSelfValues } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: MVRegister) throws -> MVRegister { var copy = self try copy.merge(other) diff --git a/Sources/CRDTSets/GSet.swift b/Sources/CRDTSets/GSet.swift index 7acb233..cbc4a9c 100644 --- a/Sources/CRDTSets/GSet.swift +++ b/Sources/CRDTSets/GSet.swift @@ -66,6 +66,13 @@ extension GSet: CvRDT { self.formUnion(other) } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: GSet) throws -> GSet { var copy = self try copy.merge(other) diff --git a/Sources/CRDTSets/TwoPhaseSet.swift b/Sources/CRDTSets/TwoPhaseSet.swift index 30747a8..b221462 100644 --- a/Sources/CRDTSets/TwoPhaseSet.swift +++ b/Sources/CRDTSets/TwoPhaseSet.swift @@ -85,6 +85,13 @@ extension TwoPhaseSet: CvRDT { self.removedElements.formUnion(other.removedElements) } + /// An idempotent and commutative function which attempts to produce a new instance with the + /// other instance's state merged with this instance's state. + /// + /// - Parameter other: The other instance + /// - Throws: Throws an error if the states could not be merged. + /// - Returns: A new instance which is the result of merging this instance's state with the + /// other instance's state. public func merged(_ other: TwoPhaseSet) throws -> TwoPhaseSet { var copy = self try copy.merge(other)