summaryrefslogtreecommitdiff
path: root/src/Storage/Merge.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-02-02 21:03:02 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-03 21:21:41 +0100
commit84d7c83bc85ff0862a39d6de3bd227550175ebce (patch)
tree11a517a2efb213a5c547b8505ce58ea7ab69e64c /src/Storage/Merge.hs
parent1685c44c5592fb3043bcf6d29ddd3d7659e8346b (diff)
Direct messages in shared state
Diffstat (limited to 'src/Storage/Merge.hs')
-rw-r--r--src/Storage/Merge.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Storage/Merge.hs b/src/Storage/Merge.hs
index 17b02aa..f0eaf98 100644
--- a/src/Storage/Merge.hs
+++ b/src/Storage/Merge.hs
@@ -6,6 +6,8 @@ module Storage.Merge (
ancestors,
precedes,
filterAncestors,
+
+ findProperty,
) where
import qualified Data.ByteString.Char8 as BC
@@ -58,4 +60,12 @@ precedes :: Storable a => Stored a -> Stored a -> Bool
precedes x y = x `S.member` ancestors [y]
filterAncestors :: Storable a => [Stored a] -> [Stored a]
+filterAncestors [x] = [x]
filterAncestors xs = uniq $ sort $ filter (`S.notMember` ancestors xs) xs
+
+
+findProperty :: forall a b. Storable a => (a -> Maybe b) -> [Stored a] -> [b]
+findProperty sel = map (fromJust . sel . fromStored) . filterAncestors . (findPropHeads =<<)
+ where findPropHeads :: Stored a -> [Stored a]
+ findPropHeads sobj | Just _ <- sel $ fromStored sobj = [sobj]
+ | otherwise = findPropHeads =<< previous sobj