diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2024-04-06 19:07:27 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2024-04-17 20:59:41 +0200 |
commit | 943cd6e754453f70deae6ad89c6045b42c59e9c9 (patch) | |
tree | f7ff52bfbfacacc6af7e2793c3d60651a10c71dc /src/Erebos/Set.hs | |
parent | d684bc2b012e23e3cc0dfa1195a74abac661b926 (diff) |
Chatroom service
Diffstat (limited to 'src/Erebos/Set.hs')
-rw-r--r-- | src/Erebos/Set.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Erebos/Set.hs b/src/Erebos/Set.hs index 0abe02d..c5edd56 100644 --- a/src/Erebos/Set.hs +++ b/src/Erebos/Set.hs @@ -4,6 +4,7 @@ module Erebos.Set ( emptySet, loadSet, storeSetAdd, + storeSetAddComponent, fromSetBy, ) where @@ -23,6 +24,7 @@ import Erebos.Storage.Merge import Erebos.Util data Set a = Set [Stored (SetItem (Component a))] + deriving (Eq) data SetItem a = SetItem { siPrev :: [Stored (SetItem a)] @@ -56,6 +58,12 @@ storeSetAdd st x (Set prev) = Set . (:[]) <$> wrappedStore st SetItem , siItem = toComponents x } +storeSetAddComponent :: (Mergeable a, MonadStorage m, MonadIO m) => Stored (Component a) -> Set a -> m (Set a) +storeSetAddComponent component (Set prev) = Set . (:[]) <$> mstore SetItem + { siPrev = prev + , siItem = [ component ] + } + fromSetBy :: forall a. Mergeable a => (a -> a -> Ordering) -> Set a -> [a] fromSetBy cmp (Set heads) = sortBy cmp $ map merge $ groupRelated items |