1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module Erebos.Storage.Merge (
Mergeable(..),
merge, storeMerge,
Generation,
showGeneration,
compareGeneration, generationMax,
storedGeneration,
generations, generationsBy,
ancestors,
precedes,
precedesOrEquals,
filterAncestors,
storedRoots,
walkAncestors,
findProperty,
findPropertyFirst,
storedDifference,
) where
import Data.Kind
import Erebos.Object
import Erebos.Storable
import Erebos.Storage.Graph
import Erebos.Storage.Internal
class Storable (Component a) => Mergeable a where
type Component a :: Type
mergeSorted :: [Stored (Component a)] -> a
toComponents :: a -> [Stored (Component a)]
instance Mergeable [Stored Object] where
type Component [Stored Object] = Object
mergeSorted = id
toComponents = id
merge :: Mergeable a => [Stored (Component a)] -> a
merge [] = error "merge: empty list"
merge xs = mergeSorted $ filterAncestors xs
storeMerge :: (Mergeable a, Storable a) => [Stored (Component a)] -> IO (Stored a)
storeMerge [] = error "merge: empty list"
storeMerge xs@(x : _) = wrappedStore (storedStorage x) $ mergeSorted $ filterAncestors xs
|