You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Data/Map/Misc.hs
+24-9Lines changed: 24 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
{-# LANGUAGE LambdaCase #-}
2
+
--| Additional functions for manipulating 'Map's.
2
3
moduleData.Map.Misc
3
4
(
4
5
-- * Working with Maps
@@ -10,20 +11,28 @@ module Data.Map.Misc
10
11
) where
11
12
12
13
importData.Align
13
-
importData.Either (isLeft)
14
14
importData.Map (Map)
15
15
importqualifiedData.MapasMap
16
16
importData.Maybe
17
17
importData.Set (Set)
18
18
importqualifiedData.SetasSet
19
19
importData.These
20
20
21
+
--|Produce a @'Map' k (Maybe v)@ by comparing two @'Map' k v@s, @old@ and @new@ respectively. @Just@ represents an association present in @new@ and @Nothing@
22
+
-- represents an association only present in @old@ but no longer present in @new@.
23
+
--
24
+
-- Similar to 'diffMap' but doesn't require 'Eq' on the values, thus can't tell if a value has changed or not.
--|Produce a @'Map' k (Maybe v)@ by comparing two @'Map' k v@s, @old@ and @new respectively. @Just@ represents an association present in @new@ and either not
32
+
-- present in @old@ or where the value has changed. @Nothing@ represents an association only present in @old@ but no longer present in @new@.
33
+
--
34
+
-- See also 'diffMapNoEq' for a similar but weaker version which does not require 'Eq' on the values but thus can't indicated a value not changing between
-- I think it's fine if this is lazy - it'll retain the 'a', but so would the output; we just need to make sure it's forced before we start relying on the associated FastWeak to actually be weak
148
+
--| Create a 'FastWeakTicket' directly from a value, creating a 'FastWeak' in the process
149
+
-- which can be obtained with 'getFastWeakTicketValue'.
107
150
mkFastWeakTicket::a->IO (FastWeakTicketa)
151
+
-- I think it's fine if this is lazy - it'll retain the 'a', but so would the output; we just need to make sure it's forced before we start relying on the
152
+
-- associated FastWeak to actually be weak
108
153
#ifdef GHCJS_FAST_WEAK
109
154
mkFastWeakTicket v = js_fastWeakTicket (unsafeToRawJSVal v)
110
155
@@ -119,11 +164,16 @@ mkFastWeakTicket v = do
119
164
}
120
165
#endif
121
166
167
+
--| Demote a 'FastWeakTicket'; which ensures the value is alive, to a 'FastWeak' which doesn't.
168
+
-- Note that unless the ticket for the same 'FastWeak' is held in some other way
--| Apply the insertions or deletions to a given 'DMap'.
31
34
instanceGComparek=>Patch (PatchDMapkv) where
32
35
typePatchTarget (PatchDMapkv) =DMapkv
33
36
apply (PatchDMap diff) old =Just$! insertions `DMap.union` (old `DMap.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust?
@@ -37,32 +40,43 @@ instance GCompare k => Patch (PatchDMap k v) where
37
40
Nothing->Just$Constant()
38
41
Just _ ->Nothing
39
42
43
+
--| Map a function @v a -> v' a@ over any inserts/updates in the given
44
+
-- @'PatchDMap' k v@ to produce a @'PatchDMap' k v'@.
, _nodeInfo_to =ComposeMaybe$Const2<$>MapWithMove._nodeInfo_to ni
342
343
}
343
344
345
+
--| Apply the insertions, deletions, and moves to a given 'DMap'.
344
346
instanceGComparek=>Patch (PatchDMapWithMovekv) where
345
347
typePatchTarget (PatchDMapWithMovekv) =DMapkv
346
348
apply (PatchDMapWithMove p) old =Just$! insertions `DMap.union` (old `DMap.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust?
@@ -356,8 +358,7 @@ instance GCompare k => Patch (PatchDMapWithMove k v) where
356
358
From_Delete->Just$Constant()
357
359
_ ->Nothing
358
360
359
-
--| Get the values that will be deleted or moved if the given patch is applied
360
-
-- to the given 'DMap'.
361
+
--| Get the values that will be replaced, deleted, or moved if the given patch is applied to the given 'DMap'.
0 commit comments