packages feed

crdt-event-fold 1.1.0.0 → 1.2.0.0

raw patch · 3 files changed

+50/−27 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

crdt-event-fold.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                crdt-event-fold-version:             1.1.0.0+version:             1.2.0.0 synopsis:            Garbage collected event folding CRDT. description:         Garbage collected event folding CRDT. Consistently                      apply arbitrary operations to replicated data.
src/Data/CRDT/EventFold.hs view
@@ -691,28 +691,25 @@   'EventId' is so that you can use it to tell when the participation   event has reached the infimum. See also: 'infimumId' -}-participate :: (Ord p, Event e)+participate :: forall o p e. (Ord p, Event e)   => p {- ^ The local participant. -}   -> p {- ^ The participant being added. -}   -> EventFold o p e   -> (EventId p, UpdateResult o p e) participate self peer (EventFold ef) =-  let-    eid = nextId self ef-  in     (       eid,       let         (ef2, outputs1) =           acknowledge-          self-          ef {-            psEvents =-              Map.insert-                eid-                (Identity (Join peer), mempty)-                (psEvents ef)-          }+            self+            ef {+              psEvents =+                Map.insert+                  eid+                  (Identity (Join peer), mempty)+                  (psEvents ef)+            }         (ef3, outputs2) = acknowledge peer ef2       in         UpdateResult {@@ -725,25 +722,47 @@           urNeedsPropagation = True         }     )+  where+    eid :: EventId p+    eid = nextId self ef   {- |   Indicate that a participant is removing itself from participating in   the distributed 'EventFold'. -}-disassociate :: (Ord p)-  => p-  -> p-  -> EventFold o p e+disassociate :: forall o p e. (Event e, Ord p)+  => p {- ^ The peer removing itself from participation. -}   -> EventFold o p e-disassociate self peer (EventFold ef) =-  EventFold ef {-    psEvents =-      Map.insert-        (nextId self ef)-        (Identity (UnJoin peer), mempty)-        (psEvents ef)-  }+  -> (EventId p, UpdateResult o p e)+disassociate peer (EventFold ef) =+    let+      (ef2, outputs) =+        acknowledge+          peer+          ef {+            psEvents =+              Map.insert+                eid+                (Identity (UnJoin peer), mempty)+                (psEvents ef)+          }+    in+      (+        eid,+        UpdateResult {+          urEventFold = EventFold ef2,+          urOutputs = outputs,+          {- +            By definition, we have added some new information that+            needs propagating.+          -}+          urNeedsPropagation = True+        }+      )+  where+    eid :: EventId p+    eid = nextId peer ef   {- |
test/test.hs view
@@ -11,8 +11,8 @@  import Data.CRDT.EventFold (Event(Output, State, apply),   EventResult(Pure), UpdateResult(urEventFold, urNeedsPropagation,-  urOutputs), EventFold, diffMerge, divergent, event, events, fullMerge,-  infimumValue, new, participate)+  urOutputs), EventFold, diffMerge, disassociate, divergent, event,+  events, fullMerge, infimumValue, new, participate) import Test.Hspec (describe, hspec, it, shouldBe, shouldNotBe)  @@ -196,6 +196,10 @@       show (divergent a) `shouldBe` "fromList [('b',Eid 4 'b'),('c',Eid 4 'a')]"       show (divergent b) `shouldBe` "fromList [('a',Eid 2 'a')]"       show (divergent c) `shouldBe` "fromList [('b',Eid 2 'a')]"++      do {- A world where c leaves.  -}+        let (_eid, r) = disassociate 'c' c+        show (urEventFold r) `shouldBe` "EventFold {unEventFold = EventFoldF {psOrigin = 0, psInfimum = Infimum {eventId = Eid 2 'a', participants = fromList \"ab\", stateValue = -3}, psEvents = fromList [(Eid 3 'a',(Identity (Event Inc),fromList \"ac\")),(Eid 4 'a',(Identity (Join 'c'),fromList \"ac\")),(Eid 5 'c',(Identity (UnJoin 'c'),fromList \"c\"))]}}"        {- | 'a' sends update to 'b'.  -}       let Right r = diffMerge 'b' b (events 'b' a)