reflex-0.5.0.1: Higher-order Functional Reactive Programming

Safe HaskellNone
LanguageHaskell98

Reflex.Patch.MapWithMove

Description

Patches on Map that can insert, delete, and move values from one key to another

Synopsis

Documentation

newtype PatchMapWithMove k v Source #

Patch a DMap with additions, deletions, and moves. Invariant: If key k1 is coming from From_Move k2, then key k2 should be going to Just k1, and vice versa. There should never be any unpaired From/To keys.

Constructors

PatchMapWithMove (Map k (NodeInfo k v)) 
Instances
Functor (PatchMapWithMove k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fmap :: (a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #

(<$) :: a -> PatchMapWithMove k b -> PatchMapWithMove k a #

Foldable (PatchMapWithMove k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fold :: Monoid m => PatchMapWithMove k m -> m #

foldMap :: Monoid m => (a -> m) -> PatchMapWithMove k a -> m #

foldr :: (a -> b -> b) -> b -> PatchMapWithMove k a -> b #

foldr' :: (a -> b -> b) -> b -> PatchMapWithMove k a -> b #

foldl :: (b -> a -> b) -> b -> PatchMapWithMove k a -> b #

foldl' :: (b -> a -> b) -> b -> PatchMapWithMove k a -> b #

foldr1 :: (a -> a -> a) -> PatchMapWithMove k a -> a #

foldl1 :: (a -> a -> a) -> PatchMapWithMove k a -> a #

toList :: PatchMapWithMove k a -> [a] #

null :: PatchMapWithMove k a -> Bool #

length :: PatchMapWithMove k a -> Int #

elem :: Eq a => a -> PatchMapWithMove k a -> Bool #

maximum :: Ord a => PatchMapWithMove k a -> a #

minimum :: Ord a => PatchMapWithMove k a -> a #

sum :: Num a => PatchMapWithMove k a -> a #

product :: Num a => PatchMapWithMove k a -> a #

Traversable (PatchMapWithMove k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

traverse :: Applicative f => (a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b) #

sequenceA :: Applicative f => PatchMapWithMove k (f a) -> f (PatchMapWithMove k a) #

mapM :: Monad m => (a -> m b) -> PatchMapWithMove k a -> m (PatchMapWithMove k b) #

sequence :: Monad m => PatchMapWithMove k (m a) -> m (PatchMapWithMove k a) #

(Eq k, Eq v) => Eq (PatchMapWithMove k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

(Ord k, Ord v) => Ord (PatchMapWithMove k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

(Show k, Show v) => Show (PatchMapWithMove k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Ord k => Semigroup (PatchMapWithMove k v) Source #

Compose patches having the same effect as applying the patches in turn: applyAlways (p <> q) == applyAlways p . applyAlways q

Instance details

Defined in Reflex.Patch.MapWithMove

Ord k => Monoid (PatchMapWithMove k v) Source #

Compose patches having the same effect as applying the patches in turn: applyAlways (p <> q) == applyAlways p . applyAlways q

Instance details

Defined in Reflex.Patch.MapWithMove

Ord k => Patch (PatchMapWithMove k v) Source #

Apply the insertions, deletions, and moves to a given Map

Instance details

Defined in Reflex.Patch.MapWithMove

Associated Types

type PatchTarget (PatchMapWithMove k v) :: * Source #

type PatchTarget (PatchMapWithMove k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

data NodeInfo k v Source #

Holds the information about each key: where its new value should come from, and where its old value should go to

Constructors

NodeInfo 

Fields

  • _nodeInfo_from :: !(From k v)

    Where do we get the new value for this key?

  • _nodeInfo_to :: !(To k)

    If the old value is being kept (i.e. moved rather than deleted or replaced), where is it going?

Instances
Functor (NodeInfo k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fmap :: (a -> b) -> NodeInfo k a -> NodeInfo k b #

(<$) :: a -> NodeInfo k b -> NodeInfo k a #

Foldable (NodeInfo k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fold :: Monoid m => NodeInfo k m -> m #

foldMap :: Monoid m => (a -> m) -> NodeInfo k a -> m #

foldr :: (a -> b -> b) -> b -> NodeInfo k a -> b #

foldr' :: (a -> b -> b) -> b -> NodeInfo k a -> b #

foldl :: (b -> a -> b) -> b -> NodeInfo k a -> b #

foldl' :: (b -> a -> b) -> b -> NodeInfo k a -> b #

foldr1 :: (a -> a -> a) -> NodeInfo k a -> a #

foldl1 :: (a -> a -> a) -> NodeInfo k a -> a #

toList :: NodeInfo k a -> [a] #

null :: NodeInfo k a -> Bool #

length :: NodeInfo k a -> Int #

elem :: Eq a => a -> NodeInfo k a -> Bool #

maximum :: Ord a => NodeInfo k a -> a #

minimum :: Ord a => NodeInfo k a -> a #

sum :: Num a => NodeInfo k a -> a #

product :: Num a => NodeInfo k a -> a #

Traversable (NodeInfo k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

traverse :: Applicative f => (a -> f b) -> NodeInfo k a -> f (NodeInfo k b) #

sequenceA :: Applicative f => NodeInfo k (f a) -> f (NodeInfo k a) #

mapM :: Monad m => (a -> m b) -> NodeInfo k a -> m (NodeInfo k b) #

sequence :: Monad m => NodeInfo k (m a) -> m (NodeInfo k a) #

(Eq v, Eq k) => Eq (NodeInfo k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

(==) :: NodeInfo k v -> NodeInfo k v -> Bool #

(/=) :: NodeInfo k v -> NodeInfo k v -> Bool #

(Ord v, Ord k) => Ord (NodeInfo k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

compare :: NodeInfo k v -> NodeInfo k v -> Ordering #

(<) :: NodeInfo k v -> NodeInfo k v -> Bool #

(<=) :: NodeInfo k v -> NodeInfo k v -> Bool #

(>) :: NodeInfo k v -> NodeInfo k v -> Bool #

(>=) :: NodeInfo k v -> NodeInfo k v -> Bool #

max :: NodeInfo k v -> NodeInfo k v -> NodeInfo k v #

min :: NodeInfo k v -> NodeInfo k v -> NodeInfo k v #

(Read v, Read k) => Read (NodeInfo k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

(Show v, Show k) => Show (NodeInfo k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

showsPrec :: Int -> NodeInfo k v -> ShowS #

show :: NodeInfo k v -> String #

showList :: [NodeInfo k v] -> ShowS #

data From k v Source #

Describe how a key's new value should be produced

Constructors

From_Insert v

Insert the given value here

From_Delete

Delete the existing value, if any, from here

From_Move !k

Move the value here from the given key

Instances
Functor (From k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fmap :: (a -> b) -> From k a -> From k b #

(<$) :: a -> From k b -> From k a #

Foldable (From k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

fold :: Monoid m => From k m -> m #

foldMap :: Monoid m => (a -> m) -> From k a -> m #

foldr :: (a -> b -> b) -> b -> From k a -> b #

foldr' :: (a -> b -> b) -> b -> From k a -> b #

foldl :: (b -> a -> b) -> b -> From k a -> b #

foldl' :: (b -> a -> b) -> b -> From k a -> b #

foldr1 :: (a -> a -> a) -> From k a -> a #

foldl1 :: (a -> a -> a) -> From k a -> a #

toList :: From k a -> [a] #

null :: From k a -> Bool #

length :: From k a -> Int #

elem :: Eq a => a -> From k a -> Bool #

maximum :: Ord a => From k a -> a #

minimum :: Ord a => From k a -> a #

sum :: Num a => From k a -> a #

product :: Num a => From k a -> a #

Traversable (From k) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

traverse :: Applicative f => (a -> f b) -> From k a -> f (From k b) #

sequenceA :: Applicative f => From k (f a) -> f (From k a) #

mapM :: Monad m => (a -> m b) -> From k a -> m (From k b) #

sequence :: Monad m => From k (m a) -> m (From k a) #

(Eq v, Eq k) => Eq (From k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

(==) :: From k v -> From k v -> Bool #

(/=) :: From k v -> From k v -> Bool #

(Ord v, Ord k) => Ord (From k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

compare :: From k v -> From k v -> Ordering #

(<) :: From k v -> From k v -> Bool #

(<=) :: From k v -> From k v -> Bool #

(>) :: From k v -> From k v -> Bool #

(>=) :: From k v -> From k v -> Bool #

max :: From k v -> From k v -> From k v #

min :: From k v -> From k v -> From k v #

(Read v, Read k) => Read (From k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

readsPrec :: Int -> ReadS (From k v) #

readList :: ReadS [From k v] #

readPrec :: ReadPrec (From k v) #

readListPrec :: ReadPrec [From k v] #

(Show v, Show k) => Show (From k v) Source # 
Instance details

Defined in Reflex.Patch.MapWithMove

Methods

showsPrec :: Int -> From k v -> ShowS #

show :: From k v -> String #

showList :: [From k v] -> ShowS #

type To = Maybe Source #

Describe where a key's old value will go. If this is Just, that means the key's old value will be moved to the given other key; if it is Nothing, that means it will be deleted.

patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v) Source #

Create a PatchMapWithMove, validating it

patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v Source #

Create a PatchMapWithMove that inserts everything in the given Map

unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo k v) Source #

Extract the internal representation of the PatchMapWithMove

insertMapKey :: k -> v -> PatchMapWithMove k v Source #

Make a PatchMapWithMove k v which has the effect of inserting or updating a value v to the given key k, like insert.

moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v Source #

Make a PatchMapWithMove k v which has the effect of moving the value from the first key k to the second key k, equivalent to:

    delete src (maybe map (insert dst) (Map.lookup src map))

swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v Source #

Make a PatchMapWithMove k v which has the effect of swapping two keys in the mapping, equivalent to:

    let aMay = Map.lookup a map
        bMay = Map.lookup b map
    in maybe id (Map.insert a) (bMay mplus aMay)
     . maybe id (Map.insert b) (aMay mplus bMay)
     . Map.delete a . Map.delete b $ map

deleteMapKey :: k -> PatchMapWithMove k v Source #

Make a PatchMapWithMove k v which has the effect of deleting a key in the mapping, equivalent to delete.

unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v Source #

Wrap a Map k (NodeInfo k v) representing patch changes into a PatchMapWithMove k v, without checking any invariants.

Warning: when using this function, you must ensure that the invariants of PatchMapWithMove are preserved; they will not be checked.

patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v] Source #

Returns all the new elements that will be added to the Map.

patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v Source #

Return a Map k v with all the inserts/updates from the given PatchMapWithMove k v.

patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v Source #

Create a PatchMapWithMove that, if applied to the given Map, will sort its values using the given ordering function. The set keys of the Map is not changed.

patchThatChangesAndSortsMapWith :: forall k v. (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v Source #

Create a PatchMapWithMove that, if applied to the first Map provided, will produce a Map with the same values as the second Map but with the values sorted with the given ordering function.

patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v Source #

Create a PatchMapWithMove that, if applied to the first Map provided, will produce the second Map.

nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v Source #

Change the From value of a NodeInfo

nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v) Source #

Change the From value of a NodeInfo, using a Functor (or Applicative, Monad, etc.) action to get the new value

nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v Source #

Set the To field of a NodeInfo

data Fixup k v Source #

Helper data structure used for composing patches using the monoid instance.

Constructors

Fixup_Delete 
Fixup_Update (These (From k v) (To k))