on develop help sign in
A couple more tweaks
commit1647b9c62b239ffc601f0630d854a0d139d424e3 authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 18 Apr 2017, 21:06 (9 years ago) parent313b957
3 files changed+11−9
src/Data/Functor/Misc.hs−1 src/Reflex/Patch/DMap.hs+5−1 src/Reflex/Patch/DMapWithMove.hs+6−7
src/Data/Functor/Misc.hs−1
@@ -54,7 +54,6 @@ import Data.GADT.Compare
5454import Data.GADT.Show
5555import Data.Map (Map)
5656import qualified Data.Map as Map
57−import Data.Maybe
5857import Data.Some (Some)
5958import qualified Data.Some as Some
6059import Data.These
src/Reflex/Patch/DMap.hs+5−1
@@ -20,7 +20,7 @@ import Data.Some (Some)
2020
2121-- | A set of changes to a 'DMap'. Any element may be inserted/updated or
2222-- deleted.
23−newtype PatchDMap k v = PatchDMap (DMap k (ComposeMaybe v))
23+newtype PatchDMap k v = PatchDMap { unPatchDMap :: DMap k (ComposeMaybe v) }
2424
2525deriving instance GCompare k => Semigroup (PatchDMap k v)
2626
@@ -55,3 +55,7 @@ const2PatchDMapWith f (PatchMap p) = PatchDMap $ DMap.fromDistinctAscList $ g <$
5555 where g :: (k, Maybe v) -> DSum (Const2 k a) (ComposeMaybe f)
5656 g (k, e) = Const2 k :=> ComposeMaybe (f <$> e)
5757
58+-- | Get the values that will be deleted if the given patch is applied to the
59+-- given 'DMap'. Includes values that will be replaced.
60+getDeletions :: GCompare k => PatchDMap k v -> DMap k v' -> DMap k v'
61+getDeletions (PatchDMap p) m = DMap.intersectionWithKey (\_ v _ -> v) m p
src/Reflex/Patch/DMapWithMove.hs+6−7
@@ -22,6 +22,7 @@ import qualified Data.Dependent.Map as DMap
2222import Data.Dependent.Sum (ShowTag (..), EqTag (..))
2323import Data.Functor.Constant
2424import Data.Functor.Misc
25+import Data.Functor.Product
2526import Data.GADT.Compare (GEq (..))
2627import Data.GADT.Show (GShow (..))
2728import qualified Data.Map as Map
@@ -266,10 +267,8 @@ instance GCompare k => Patch (PatchDMapWithMove k v) where
266267 From_Delete -> Just $ Constant ()
267268 _ -> Nothing
268269
269−-- | Get the values that will be deleted if the given patch is applied to the
270−-- given 'DMap'
271−getDeletions :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k v'
272−getDeletions (PatchDMapWithMove p) m = DMap.mapMaybeWithKey (\_ -> getComposeMaybe) $ DMap.intersectionWithKey f p m
273− where f _ ni v = ComposeMaybe $ case getComposeMaybe $ _nodeInfo_to ni of
274− Just _ -> Nothing
275− Nothing -> Just v
270+-- | Get the values that will be deleted or moved if the given patch is applied
271+-- to the given 'DMap'.
272+getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k))
273+getDeletionsAndMoves (PatchDMapWithMove p) m = DMap.intersectionWithKey f m p
274+ where f _ v ni = Pair v $ _nodeInfo_to ni