2{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE TypeFamilies #-}
4module Reflex.Patch.Map where
6import Reflex.Patch.Class
10import qualified Data.Map as Map
13-- | A set of changes to a 'Map'. Any element may be inserted/updated or
15newtype PatchMap k v = PatchMap { unPatchMap :: Map k (Maybe v) }
17instance Ord k => Patch (PatchMap k v) where
18 type PatchTarget (PatchMap k v) = Map k v
19 apply (PatchMap p) old = Just $! insertions `Map.union` (old `Map.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?
20 where insertions = Map.mapMaybeWithKey (const id) p
21 deletions = Map.mapMaybeWithKey (const nothingToJust) p
26instance Ord k => Semigroup (PatchMap k v) where
27 PatchMap a <> PatchMap b = PatchMap $ a `mappend` b --TODO: Add a semigroup instance for Map
28 -- PatchMap is idempotent, so stimes n is id for every n
29#if MIN_VERSION_semigroups(0,17,0)
30 stimes = stimesIdempotentMonoid
32 times1p n x = case compare n 0 of
33 LT -> error "stimesIdempotentMonoid: negative multiplier"
38instance Ord k => Monoid (PatchMap k v) where
39 mempty = PatchMap mempty
42instance Functor (PatchMap k) where
43 fmap f = PatchMap . fmap (fmap f) . unPatchMap
45-- | Returns all the new elements that will be added to the 'Map'
46patchMapNewElements :: PatchMap k v -> [v]
47patchMapNewElements (PatchMap p) = catMaybes $ Map.elems p
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list