| Copyright | © 2022–2025 Jonathan Knowles | 
|---|---|
| License | Apache-2.0 | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.MonoidMap.Internal
Description
Provides internal operations for the MonoidMap type.
Synopsis
- newtype MonoidMap k v = MonoidMap (Map k (NonNull v))
- newtype NonNull v = UnsafeNonNull {- getNonNull :: v
 
- empty :: MonoidMap k v
- fromList :: (Ord k, MonoidNull v) => [(k, v)] -> MonoidMap k v
- fromListWith :: (Ord k, MonoidNull v) => (v -> v -> v) -> [(k, v)] -> MonoidMap k v
- fromMap :: MonoidNull v => Map k v -> MonoidMap k v
- fromMapWith :: MonoidNull v2 => (v1 -> v2) -> Map k v1 -> MonoidMap k v2
- fromSet :: MonoidNull v => (k -> v) -> Set k -> MonoidMap k v
- singleton :: (Ord k, MonoidNull v) => k -> v -> MonoidMap k v
- toList :: MonoidMap k v -> [(k, v)]
- toMap :: MonoidMap k v -> Map k v
- get :: (Ord k, Monoid v) => k -> MonoidMap k v -> v
- set :: (Ord k, MonoidNull v) => k -> v -> MonoidMap k v -> MonoidMap k v
- adjust :: (Ord k, MonoidNull v) => (v -> v) -> k -> MonoidMap k v -> MonoidMap k v
- nullify :: Ord k => k -> MonoidMap k v -> MonoidMap k v
- null :: MonoidMap k v -> Bool
- nullKey :: Ord k => k -> MonoidMap k v -> Bool
- nonNull :: MonoidMap k v -> Bool
- nonNullCount :: MonoidMap k v -> Int
- nonNullKey :: Ord k => k -> MonoidMap k v -> Bool
- nonNullKeys :: MonoidMap k v -> Set k
- take :: Int -> MonoidMap k v -> MonoidMap k v
- drop :: Int -> MonoidMap k v -> MonoidMap k v
- splitAt :: Int -> MonoidMap k a -> (MonoidMap k a, MonoidMap k a)
- filter :: (v -> Bool) -> MonoidMap k v -> MonoidMap k v
- filterKeys :: (k -> Bool) -> MonoidMap k v -> MonoidMap k v
- filterWithKey :: (k -> v -> Bool) -> MonoidMap k v -> MonoidMap k v
- partition :: (v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
- partitionKeys :: (k -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
- partitionWithKey :: (k -> v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
- map :: MonoidNull v2 => (v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
- mapKeys :: (Ord k2, MonoidNull v) => (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
- mapKeysWith :: (Ord k2, MonoidNull v) => (v -> v -> v) -> (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
- mapWithKey :: MonoidNull v2 => (k -> v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
- foldl :: (r -> v -> r) -> r -> MonoidMap k v -> r
- foldl' :: (r -> v -> r) -> r -> MonoidMap k v -> r
- foldr :: (v -> r -> r) -> r -> MonoidMap k v -> r
- foldr' :: (v -> r -> r) -> r -> MonoidMap k v -> r
- foldlWithKey :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r
- foldlWithKey' :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r
- foldrWithKey :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r
- foldrWithKey' :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r
- foldMapWithKey :: Monoid r => (k -> v -> r) -> MonoidMap k v -> r
- foldMapWithKey' :: Monoid r => (k -> v -> r) -> MonoidMap k v -> r
- traverse :: (Applicative t, MonoidNull v2) => (v1 -> t v2) -> MonoidMap k v1 -> t (MonoidMap k v2)
- traverseWithKey :: (Applicative t, MonoidNull v2) => (k -> v1 -> t v2) -> MonoidMap k v1 -> t (MonoidMap k v2)
- mapAccumL :: MonoidNull v2 => (s -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2)
- mapAccumLWithKey :: MonoidNull v2 => (s -> k -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2)
- mapAccumR :: MonoidNull v2 => (s -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2)
- mapAccumRWithKey :: MonoidNull v2 => (s -> k -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2)
- append :: (Ord k, MonoidNull v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- minus :: (Ord k, MonoidNull v, Group v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- minusMaybe :: (Ord k, MonoidNull v, Reductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
- monus :: (Ord k, MonoidNull v, Monus v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- invert :: (MonoidNull v, Group v) => MonoidMap k v -> MonoidMap k v
- power :: (Integral i, MonoidNull v, Group v) => MonoidMap k v -> i -> MonoidMap k v
- isSubmapOf :: (Ord k, Monoid v, Reductive v) => MonoidMap k v -> MonoidMap k v -> Bool
- isSubmapOfBy :: (Ord k, Monoid v1, Monoid v2) => (v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
- disjoint :: (Ord k, GCDMonoid v, MonoidNull v) => MonoidMap k v -> MonoidMap k v -> Bool
- disjointBy :: (Ord k, Monoid v1, Monoid v2) => (v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
- intersection :: (Ord k, MonoidNull v, GCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- intersectionWith :: (Ord k, MonoidNull v3) => (v1 -> v2 -> v3) -> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
- intersectionWithA :: (Applicative f, Ord k, MonoidNull v3) => (v1 -> v2 -> f v3) -> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
- union :: (Ord k, MonoidNull v, LCMMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- unionWith :: (Ord k, Monoid v1, Monoid v2, MonoidNull v3) => (v1 -> v2 -> v3) -> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
- unionWithA :: (Applicative f, Ord k, Monoid v1, Monoid v2, MonoidNull v3) => (v1 -> v2 -> f v3) -> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
- isPrefixOf :: (Ord k, Monoid v, LeftReductive v) => MonoidMap k v -> MonoidMap k v -> Bool
- stripPrefix :: (Ord k, MonoidNull v, LeftReductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
- commonPrefix :: (Ord k, MonoidNull v, LeftGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- stripCommonPrefix :: (Ord k, MonoidNull v, LeftGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
- isSuffixOf :: (Ord k, Monoid v, RightReductive v) => MonoidMap k v -> MonoidMap k v -> Bool
- stripSuffix :: (Ord k, MonoidNull v, RightReductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
- commonSuffix :: (Ord k, MonoidNull v, RightGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- stripCommonSuffix :: (Ord k, MonoidNull v, RightGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
- overlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- stripPrefixOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- stripSuffixOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v
- stripOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
Types
newtype MonoidMap k v Source #
Instances
Constructors
| UnsafeNonNull | |
| Fields 
 | |
General operations
Construction
fromList :: (Ord k, MonoidNull v) => [(k, v)] -> MonoidMap k v Source #
\(O(n \log n)\). Constructs a MonoidMap from a list of key-value pairs.
If the list contains more than one value for the same key, values are
 combined together in the order that they appear with the (<>) operator.
Satisfies the following property for all possible keys k:
getk (fromListkvs)==foldMapsnd(filter((==k) . fst) kvs)
Satisfies the following round-trip property:
fromList(toListm)==m
Examples
Arguments
| :: (Ord k, MonoidNull v) | |
| => (v -> v -> v) | Function with which to combine values for duplicate keys. | 
| -> [(k, v)] | |
| -> MonoidMap k v | 
\(O(n \log n)\). Constructs a MonoidMap from a list of key-value pairs,
   with a combining function for values.
If the list contains more than one value for the same key, values are combined together in the order that they appear with the given combining function.
Satisfies the following property for all possible keys k:
getk (fromListWithf kvs)==maybemempty(foldl1f) (nonEmpty(snd<$>filter((==k) . fst) kvs))
fromMapWith :: MonoidNull v2 => (v1 -> v2) -> Map k v1 -> MonoidMap k v2 Source #
\(O(n)\). Constructs a MonoidMap from an ordinary Map, applying
   the given function to all values.
Satisfies the following property for all possible keys k:
getk (fromMapWithf m)==maybememptyf (Map.lookupk m)
This function performs canonicalisation of null values, and has a time
 complexity that is linear in the size of the map.
Since: 0.0.4.0
fromSet :: MonoidNull v => (k -> v) -> Set k -> MonoidMap k v Source #
\(O(n)\). Constructs a MonoidMap from a Set and a function from
   keys to values.
Satisfies the following property for all possible keys k:
getk (fromSetf ks)==ifSet.memberk ks then f k elsemempty
This function performs canonicalisation of null values, and has a time
 complexity that is linear in the size of the set.
Since: 0.0.2.0
Deconstruction
toList :: MonoidMap k v -> [(k, v)] Source #
\(O(n)\). Converts a MonoidMap to a list of key-value pairs, where the
   keys are in ascending order.
The result only includes entries with values that are not null.
Satisfies the following round-trip property:
fromList(toListm)==m
The resulting list is sorted in ascending key order:
sortOnfst(toListm)==toListm
Lookup
Modification
Membership
nonNull :: MonoidMap k v -> Bool Source #
\(O(1)\). Returns True if (and only if) the map contains at least one
   value that is not null.
Satisfies the following property:
nonNullm==(∃ k.nonNullKeyk m)
nonNullCount :: MonoidMap k v -> Int Source #
\(O(1)\). Returns a count of all values in the map that are not null.
Satisfies the following property:
nonNullCountm==size(nonNullKeysm)
nonNullKeys :: MonoidMap k v -> Set k Source #
\(O(n)\). Returns the set of keys associated with values that are not
   null.
Satisfies the following property:
k`member`(nonNullKeysm)==nonNullKeyk m
Slicing
splitAt :: Int -> MonoidMap k a -> (MonoidMap k a, MonoidMap k a) Source #
\(O(\log n)\). Splits a map into two slices.
This function is equivalent to a combination of take and drop:
splitAtn m==(taken m,dropn m)
The resulting maps can be combined to reproduce the original map:
splitAtn m&\(m1, m2) -> m1<>m2==m
The resulting maps have disjoint sets of non-null entries:
splitAtn m&\(m1, m2) ->disjoint(nonNullKeysm1) (nonNullKeysm2)
Filtering
filter :: (v -> Bool) -> MonoidMap k v -> MonoidMap k v Source #
\(O(n)\). Filters a map according to a predicate on values.
Satisfies the following property for all possible keys k:
getk (filterf m)==if f (getk m) thengetk m elsemempty
The resulting map is identical to that obtained by constructing a map from a filtered list of key-value pairs:
filterf m==fromList(filter(f .snd) (toListm))
filterKeys :: (k -> Bool) -> MonoidMap k v -> MonoidMap k v Source #
\(O(n)\). Filters a map according to a predicate on keys.
Satisfies the following property for all possible keys k:
getk (filterKeysf m)==if f k thengetk m elsemempty
The resulting map is identical to that obtained by constructing a map from a filtered list of key-value pairs:
filterf m==fromList(filter(f .fst) (toListm))
filterWithKey :: (k -> v -> Bool) -> MonoidMap k v -> MonoidMap k v Source #
\(O(n)\). Filters a map according to a predicate on keys and values.
Satisfies the following property for all possible keys k:
getk (filterWithKeyf m)==if f k (getk m) thengetk m elsemempty
The resulting map is identical to that obtained by constructing a map from a filtered list of key-value pairs:
filterWithKeyf m==fromList(filter(uncurryf) (toListm))
Partitioning
partition :: (v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v) Source #
\(O(n)\). Partitions a map according to a predicate on values.
Satisfies the following property:
partitionf m==(filterf m ,filter(not. f) m )
The resulting maps can be combined to reproduce the original map:
partitionf m&\(m1, m2) -> m1<>m2==m
The resulting maps have disjoint sets of non-null entries:
partitionf m&\(m1, m2) ->disjoint(nonNullKeysm1) (nonNullKeysm2)
partitionKeys :: (k -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v) Source #
\(O(n)\). Partitions a map according to a predicate on keys.
Satisfies the following property:
partitionKeysf m==(filterKeysf m ,filterKeys(not. f) m )
The resulting maps can be combined to reproduce the original map:
partitionKeysf m&\(m1, m2) -> m1<>m2==m
The resulting maps have disjoint sets of non-null entries:
partitionKeysf m&\(m1, m2) ->disjoint(nonNullKeysm1) (nonNullKeysm2)
partitionWithKey :: (k -> v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v) Source #
\(O(n)\). Partitions a map according to a predicate on keys and values.
Satisfies the following property:
partitionWithKeyf m==(filterWithKeyf m ,filterWithKey((fmap.fmap)notf) m )
The resulting maps can be combined to reproduce the original map:
partitionWithKeyf m&\(m1, m2) -> m1<>m2==m
The resulting maps have disjoint sets of non-null entries:
partitionWithKeyf m&\(m1, m2) ->disjoint(nonNullKeysm1) (nonNullKeysm2)
Mapping
map :: MonoidNull v2 => (v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2 Source #
\(O(n)\). Applies a function to all non-null values of a MonoidMap.
Satisfies the following properties for all functions f:
(getk m==mempty) ==> (getk (mapf m)==mempty) (getk m/=mempty) ==> (getk (mapf m)==f (getk m))
Conditional properties
If applying function f to mempty produces mempty, then the
 following additional properties hold:
(fmempty==mempty) ==> (∀ k.getk (mapf m)==f (getk m))
(fmempty==mempty) ==> (∀ g.map(f . g) m==mapf (mapg m))
mapKeys :: (Ord k2, MonoidNull v) => (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v Source #
\(O(n \log n)\). Applies a function to all the keys of a MonoidMap that
   are associated with non-null values.
If the resultant map would contain more than one value for the same key,
 values are combined together in ascending key order with the (<>)
 operator.
Satisfies the following property for all possible keys k:
getk (mapKeysf m)==foldMap(`get`m) (filter((==) k . f) (nonNullKeysm))
Arguments
| :: (Ord k2, MonoidNull v) | |
| => (v -> v -> v) | Function with which to combine values for duplicate keys. | 
| -> (k1 -> k2) | |
| -> MonoidMap k1 v | |
| -> MonoidMap k2 v | 
\(O(n \log n)\). Applies a function to all the keys of a MonoidMap that
   are associated with non-null values, with a combining function for
   values.
If the resultant map would contain more than one value for the same key, values are combined together in ascending key order with the given combining function.
Satisfies the following property:
mapKeysWithc f==fromListWithc .fmap(firstf) .toList
mapWithKey :: MonoidNull v2 => (k -> v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2 Source #
\(O(n)\). Applies a key-dependent function to all non-null values of
   a MonoidMap.
Satisfies the following properties for all functions f:
(nonNullKeyk m) ==> (getk (mapWithKeyf m)==f k (getk m)) (nullKeyk m) ==> (getk (mapWithKeyf m)==mempty)
Since: 0.0.3.0
Folding
foldl' :: (r -> v -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). A strict version of foldl.
Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Since: 0.0.1.7
foldr' :: (v -> r -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). A strict version of foldr.
Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Since: 0.0.1.7
foldlWithKey :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). Folds over the keys and values in the map using the given left-associative binary operator.
Satisfies the following property:
foldlWithKeyf r m==Map.foldlWithKeyf r (toMapm)
Since: 0.0.1.7
foldlWithKey' :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). A strict version of foldlWithKey.
Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Since: 0.0.1.7
foldrWithKey :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). Folds over the keys and values in the map using the given right-associative binary operator.
Satisfies the following property:
foldrWithKeyf r m==Map.foldrWithKeyf r (toMapm)
Since: 0.0.1.7
foldrWithKey' :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r Source #
\(O(n)\). A strict version of foldrWithKey.
Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Since: 0.0.1.7
foldMapWithKey :: Monoid r => (k -> v -> r) -> MonoidMap k v -> r Source #
\(O(n)\). Folds over the keys and values in the map using the given monoid.
Satisfies the following property:
foldMapWithKeyf m==Map.foldMapWithKeyf (toMapm)
Since: 0.0.1.7
foldMapWithKey' :: Monoid r => (k -> v -> r) -> MonoidMap k v -> r Source #
\(O(n)\). A strict version of foldMapWithKey.
Each application of mappend is evaluated before using the result in the
 next application.
Since: 0.0.1.8
Traversal
traverse :: (Applicative t, MonoidNull v2) => (v1 -> t v2) -> MonoidMap k v1 -> t (MonoidMap k v2) Source #
traverseWithKey :: (Applicative t, MonoidNull v2) => (k -> v1 -> t v2) -> MonoidMap k v1 -> t (MonoidMap k v2) Source #
\(O(n)\). Traverses over the keys and values of a map using the given function.
Satisfies the following property:
traverseWithKeyf m==fmapfromMap(Map.traverseWithKeyf (toMapm))
Since: 0.0.1.9
mapAccumL :: MonoidNull v2 => (s -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2) Source #
mapAccumLWithKey :: MonoidNull v2 => (s -> k -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2) Source #
\(O(n)\). Threads an accumulating argument through the map in ascending order of keys.
Satisfies the following property:
mapAccumLWithKeyf s m==fmapfromMap(Map.mapAccumWithKeyf s (toMapm))
Since: 0.0.1.9
mapAccumR :: MonoidNull v2 => (s -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2) Source #
mapAccumRWithKey :: MonoidNull v2 => (s -> k -> v1 -> (s, v2)) -> s -> MonoidMap k v1 -> (s, MonoidMap k v2) Source #
\(O(n)\). Threads an accumulating argument through the map in descending order of keys.
Satisfies the following property:
mapAccumRWithKeyf s m==fmapfromMap(Map.mapAccumRWithKeyf s (toMapm))
Since: 0.0.1.9
Monoidal operations
Association
append :: (Ord k, MonoidNull v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Appends a pair of maps together.
Uses the Semigroup operator (<>) to append each value in the first map
 to its matching value in the second map.
Satisfies the following property for all possible keys k:
getk (appendm1 m2)==getk m1<>getk m2
This function provides the definition of (<>) for the MonoidMap instance
 of Semigroup.
Examples
With String values:
>>> m1 =fromList[(1, "abc"), (2, "ij" ), (3, "p" ) ] >>> m2 =fromList[ (2, " k"), (3, "qr"), (4, "xyz")] >>> m3 =fromList[(1, "abc"), (2, "ijk"), (3, "pqr"), (4, "xyz")]
>>>appendm1 m2==m3True
>>> m1 =fromList[("a", 4), ("b", 2), ("c", 1) ] >>> m2 =fromList[ ("b", 1), ("c", 2), ("d", 4)] >>> m3 =fromList[("a", 4), ("b", 3), ("c", 3), ("d", 4)]
>>>appendm1 m2==m3True
Subtraction
minus :: (Ord k, MonoidNull v, Group v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Performs group subtraction of the second map from the first.
Uses the Group subtraction operator (~~) to subtract each value in the
 second map from its matching value in the first map.
Satisfies the following property for all possible keys k:
getk (m1`minus`m2)==getk m1~~getk m2
This function provides the definition of (~~) for the MonoidMap
 instance of Group.
Examples
With Sum Integer values, this function performs normal
 integer subtraction of matching values:
>>> m1 =fromList[("a", (-1)), ("b", 0 ), ("c", 1)] >>> m2 =fromList[("a", 1 ), ("b", 1 ), ("c", 1)] >>> m3 =fromList[("a", (-2)), ("b", (-1)), ("c", 0)]
>>> m1`minus`m2==m3True
>>> m1 =fromList[("a", (-1)), ("b", 0 ), ("c", 1 )] >>> m2 =fromList[("a", (-1)), ("b", (-1)), ("c", (-1))] >>> m3 =fromList[("a", 0 ), ("b", 1 ), ("c", 2 )]
>>> m1`minus`m2==m3True
minusMaybe :: (Ord k, MonoidNull v, Reductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v) Source #
Performs reductive subtraction of the second map from the first.
Uses the Reductive subtraction operator (</>) to subtract each value in
 the second map from its matching value in the first map.
This function produces a result if (and only if) for all possible keys
 k, it is possible to subtract the value for k in the second map
 from the value for k in the first map:
isJust(m1`minusMaybe`m2)==(∀ k.isJust(getk m1</>getk m2))
Otherwise, this function returns Nothing.
This function satisfies the following property:
all(\r ->Just(getk r)==getk m1</>getk m2) (m1`minusMaybe`m2)
This function provides the definition of (</>) for the MonoidMap
 instance of Reductive.
Examples
With Set Natural values, this function performs set
 subtraction of matching values, succeeding if (and only if) each value
 from the second map is a subset of its matching value from the first map:
f xs =fromList(fromList<$>xs)
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2])]
>>> m2 = f [("a", [     ]), ("b", [0,1,2])]
>>> m3 = f [("a", [0,1,2]), ("b", [     ])]
>>> m1`minusMaybe`m2==Justm3True
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2]), ("c", [0,1,2])]
>>> m2 = f [("a", [0    ]), ("b", [  1  ]), ("c", [    2])]
>>> m3 = f [("a", [  1,2]), ("b", [0,  2]), ("c", [0,1  ])]
>>> m1`minusMaybe`m2==Justm3True
>>> m1 = f [("a", [0,1,2    ]), ("b", [0,1,2    ]), ("c", [0,1,2    ])]
>>> m2 = f [("a", [    2,3,4]), ("b", [  1,2,3,4]), ("c", [0,1,2,3,4])]
>>> m1`minusMaybe`m2==NothingTrue
With Sum Natural values, this function
 performs ordinary subtraction of matching values, succeeding if (and only
 if) each value from the second map is less than or equal to its matching
 value from the first map:
>>> m1 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)] >>> m2 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 0)] >>> m3 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)]
>>> m1`minusMaybe`m2==Justm3True
>>> m1 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)] >>> m2 =fromList[("a", 1), ("b", 2), ("c", 3), ("d", 5)] >>> m3 =fromList[("a", 1), ("b", 1), ("c", 2), ("d", 3)]
>>> m1`minusMaybe`m2==Justm3True
>>> m1 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)] >>> m2 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)] >>> m3 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 0)]
>>> m1`minusMaybe`m2==Justm3True
>>> m1 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 8)] >>> m2 =fromList[("a", 3), ("b", 3), ("c", 5), ("d", 8)]
>>> m1`minusMaybe`m2==NothingTrue
monus :: (Ord k, MonoidNull v, Monus v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Performs monus subtraction of the second map from the first.
Uses the Monus subtraction operator (<\>) to subtract each value in
 the second map from its matching value in the first map.
Satisfies the following property for all possible keys k:
getk (m1`monus`m2)==getk m1<\>getk m2
This function provides the definition of (<\>) for the MonoidMap
 instance of Monus.
Examples
With Set Natural values, this function performs set
 subtraction of matching values:
f xs =fromList(fromList<$>xs)
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2])]
>>> m2 = f [("a", [     ]), ("b", [0,1,2])]
>>> m3 = f [("a", [0,1,2]), ("b", [     ])]
>>> m1`monus`m2==m3True
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2]), ("c", [0,1,2])]
>>> m2 = f [("a", [0    ]), ("b", [  1  ]), ("c", [    2])]
>>> m3 = f [("a", [  1,2]), ("b", [0,  2]), ("c", [0,1  ])]
>>> m1`monus`m2==m3True
>>> m1 = f [("a", [0,1,2    ]), ("b", [0,1,2    ]), ("c", [0,1,2    ])]
>>> m2 = f [("a", [    2,3,4]), ("b", [  1,2,3,4]), ("c", [0,1,2,3,4])]
>>> m3 = f [("a", [0,1      ]), ("b", [0        ]), ("c", [         ])]
>>> m1`monus`m2==m3True
With Sum Natural values, this function
 performs truncated subtraction of matching values:
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 0)] >>> m3 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)]
>>> m1`monus`m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 1), ("b", 1), ("c", 1), ("d", 1)] >>> m3 =fromList[("a", 0), ("b", 0), ("c", 1), ("d", 2)]
>>> m1`monus`m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 2), ("b", 2), ("c", 2), ("d", 2)] >>> m3 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 1)]
>>> m1`monus`m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 4), ("b", 4), ("c", 4), ("d", 4)] >>> m3 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 0)]
>>> m1`monus`m2==m3True
Inversion
invert :: (MonoidNull v, Group v) => MonoidMap k v -> MonoidMap k v Source #
Exponentiation
power :: (Integral i, MonoidNull v, Group v) => MonoidMap k v -> i -> MonoidMap k v Source #
Performs exponentiation of every value in a map.
Uses the Group exponentiation method pow to raise every value in a map
 to the power of the given exponent.
Satisfies the following property for all possible keys k:
getk (m`power`i)==getk m`pow`i
This function provides the definition of pow for the MonoidMap
 instance of Group.
Examples
With Sum Natural values, this function
 performs ordinary multiplication of all values by the given exponent:
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 0), ("b", 2), ("c", 4), ("d", 6)]
>>> m1`power`2==m2True
>>> m1 =fromList[("a", 0), ("b", 1 ), ("c", 2 ), ("d", 3 )] >>> m2 =fromList[("a", 0), ("b", (-1)), ("c", (-2)), ("d", (-3))]
>>> m1`power`(-1)==m2True
Comparison
isSubmapOf :: (Ord k, Monoid v, Reductive v) => MonoidMap k v -> MonoidMap k v -> Bool Source #
Indicates whether or not the first map is a submap of the second.
Map m1 is a submap of map m2 if (and only if) m1 can be
 subtracted from m2 with the minusMaybe operation:
m1`isSubmapOf`m2==isJust(m2`minusMaybe`m1)
Equivalently, map m1 is a submap of map m2 if (and only if) for
 all possible keys k, the value for k in m1 can be
 subtracted from the value for k in m2 with the (</>) operator:
m1`isSubmapOf`m2==(∀ k.isJust(getk m2</>getk m1))
Arguments
| :: (Ord k, Monoid v1, Monoid v2) | |
| => (v1 -> v2 -> Bool) | Function with which to compare values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> Bool | 
Indicates whether or not the first map is a submap of the second, using the given function to compare values for matching keys.
Satisfies the following property:
isSubmapOfByf m1 m2==all(\k -> f (getk m1) (getk m2)) (nonNullKeysm1)
Conditional totality
If the given comparison function f always evaluates to True
 when its first argument is mempty:
∀ v. f mempty v
Then the following property holds:
isSubmapOfByf m1 m2==(∀ k. f (getk m1) (getk m2))
disjoint :: (Ord k, GCDMonoid v, MonoidNull v) => MonoidMap k v -> MonoidMap k v -> Bool Source #
Indicates whether or not a pair of maps are disjoint.
Maps m1 and m2 are disjoint if (and only if) their intersection
 is empty:
disjointm1 m2==(intersectionm1 m2==mempty)
Equivalently, maps m1 and m2 are disjoint if (and only if) for
 all possible keys k, the values for k in m1 and m2
 have a gcd that is null:
disjointm1 m2==(∀ k.null(gcd(getk m1) (getk m2)))
Arguments
| :: (Ord k, Monoid v1, Monoid v2) | |
| => (v1 -> v2 -> Bool) | Function with which to test pairs of values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> Bool | 
Indicates whether or not a pair of maps are disjoint using the given indicator function to test pairs of values for matching keys.
Satisfies the following property:
disjointByf m1 m2==all(\k -> f (getk m1) (getk m2)) (intersection(nonNullKeysm1) (nonNullKeysm2))
Conditional totality
If the given indicator function f always evaluates to True
 when either or both of its arguments are mempty:
∀ v. (f vmempty)&&(fmemptyv)
Then the following property holds:
disjointByf m1 m2==(∀ k. f (getk m1) (getk m2))
Intersection
intersection :: (Ord k, MonoidNull v, GCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Finds the intersection of two maps.
The intersection of maps m1 and m2 is the greatest single map
 m that is a submap of both m1 and m2:
intersectionm1 m2`isSubmapOf`m1intersectionm1 m2`isSubmapOf`m2
The intersection is unique:
and[intersectionm1 m2`isSubmapOf`m , m`isSubmapOf`m1 , m`isSubmapOf`m2 ] ==> (m==intersectionm1 m2)
The following property holds for all possible keys k:
getk (intersectionm1 m2)==gcd(getk m1) (getk m2)
This function provides the definition of gcd for the MonoidMap
 instance of GCDMonoid.
Examples
With Product Natural values, this function
 computes the greatest common divisor of each pair of matching values:
>>> m1 =fromList[("a", 2), ("b", 6), ("c", 15), ("d", 35)] >>> m2 =fromList[("a", 6), ("b", 15), ("c", 35), ("d", 77)] >>> m3 =fromList[("a", 2), ("b", 3), ("c", 5), ("d", 7)]
>>>intersectionm1 m2==m3True
With Sum Natural values, this function
 computes the minimum of each pair of matching values:
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 3), ("b", 2), ("c", 1), ("d", 0)] >>> m3 =fromList[("a", 0), ("b", 1), ("c", 1), ("d", 0)]
>>>intersectionm1 m2==m3True
With Set Natural values, this function computes the
 set intersection of each pair of matching values:
f xs =fromList(fromList<$>xs)
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2  ]), ("c", [0,1,2    ])]
>>> m2 = f [("a", [0,1,2]), ("b", [  1,2,3]), ("c", [    2,3,4])]
>>> m3 = f [("a", [0,1,2]), ("b", [  1,2  ]), ("c", [    2    ])]
>>>intersectionm1 m2==m3True
Arguments
| :: (Ord k, MonoidNull v3) | |
| => (v1 -> v2 -> v3) | Function with which to combine values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> MonoidMap k v3 | 
Computes the intersection of a pair of maps using the given function to combine values for matching keys.
Satisfies the following property for all possible keys k:
getk (intersectionWithf m1 m2)==if k`member`intersection(nonNullKeysm1) (nonNullKeysm2) then f (getk m1) (getk m2) elsemempty
Conditional totality
If the given combining function f always produces mempty when
 either or both of its arguments are mempty:
(f vmempty==mempty)&&(fmemptyv==mempty)
Then the following property holds for all possible keys k:
getk (intersectionWithf m1 m2)==f (getk m1) (getk m2)
Examples
Arguments
| :: (Applicative f, Ord k, MonoidNull v3) | |
| => (v1 -> v2 -> f v3) | Function with which to combine values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> f (MonoidMap k v3) | 
An applicative version of intersectionWith.
Satisfies the following property:
runIdentity(intersectionWithA((fmap.fmap)Identityf) m1 m2)==(intersectionWithf m1 m2)
Union
union :: (Ord k, MonoidNull v, LCMMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Finds the union of two maps.
The union of maps m1 and m2 is the smallest single map m
 that includes both m1 and m2 as submaps:
m1`isSubmapOf`unionm1 m2 m2`isSubmapOf`unionm1 m2
The union is unique:
and[ m1`isSubmapOf`m , m2`isSubmapOf`m , m`isSubmapOf`unionm1 m2 ] ==> (m==unionm1 m2)
The following property holds for all possible keys k:
getk (unionm1 m2)==lcm(getk m1) (getk m2)
This function provides the definition of lcm for the MonoidMap
 instance of LCMMonoid.
Examples
With Product Natural values, this function
 computes the least common multiple of each pair of matching values:
>>> m1 =fromList[("a", 2), ("b", 6), ("c", 15), ("d", 35)] >>> m2 =fromList[("a", 6), ("b", 15), ("c", 35), ("d", 77)] >>> m3 =fromList[("a", 6), ("b", 30), ("c", 105), ("d", 385)]
>>>unionm1 m2==m3True
With Sum Natural values, this function
 computes the maximum of each pair of matching values:
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 3), ("b", 2), ("c", 1), ("d", 0)] >>> m3 =fromList[("a", 3), ("b", 2), ("c", 2), ("d", 3)]
>>>unionm1 m2==m3True
With Set Natural values, this function computes the
 set union of each pair of matching values:
f xs =fromList(fromList<$>xs)
>>> m1 = f [("a", [0,1,2]), ("b", [0,1,2  ]), ("c", [0,1,2    ])]
>>> m2 = f [("a", [0,1,2]), ("b", [  1,2,3]), ("c", [    2,3,4])]
>>> m3 = f [("a", [0,1,2]), ("b", [0,1,2,3]), ("c", [0,1,2,3,4])]
>>>unionm1 m2==m3True
Arguments
| :: (Ord k, Monoid v1, Monoid v2, MonoidNull v3) | |
| => (v1 -> v2 -> v3) | Function with which to combine values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> MonoidMap k v3 | 
Computes the union of a pair of maps using the given function to combine values for matching keys.
Satisfies the following property for all possible keys k:
getk (unionWithf m1 m2)==if k`member`union(nonNullKeysm1) (nonNullKeysm2) then f (getk m1) (getk m2) elsemempty
Conditional totality
If the given combining function f always produces mempty when
 both of its arguments are mempty:
fmemptymempty==mempty
Then the following property holds for all possible keys k:
getk (unionWithf m1 m2)==f (getk m1) (getk m2)
Examples
Arguments
| :: (Applicative f, Ord k, Monoid v1, Monoid v2, MonoidNull v3) | |
| => (v1 -> v2 -> f v3) | Function with which to combine values for matching keys. | 
| -> MonoidMap k v1 | |
| -> MonoidMap k v2 | |
| -> f (MonoidMap k v3) | 
An applicative version of unionWith.
Satisfies the following property:
runIdentity(unionWithA((fmap.fmap)Identityf) m1 m2)==(unionWithf m1 m2)
Prefixes
isPrefixOf :: (Ord k, Monoid v, LeftReductive v) => MonoidMap k v -> MonoidMap k v -> Bool Source #
Indicates whether or not the first map is a prefix of the second.
MonoidMap m1 is a prefix of MonoidMap m2 if (and only if)
 for all possible keys k, the value for k in m1 is a
 prefix of the value for k in m2:
m1`isPrefixOf`m2==(∀ k.getk m1`isPrefixOf`getk m2)
This function provides the definition of isPrefixOf for the MonoidMap
 instance of LeftReductive.
Examples
With String values:
>>> m1 =fromList[(1, "a" ), (2, "p" ), (3, "x" )] >>> m2 =fromList[(1, "abc"), (2, "pqr"), (3, "xyz")] >>> m1`isPrefixOf`m2True
>>> m1 =fromList[ (2, "p" ) ] >>> m2 =fromList[(1, "abc"), (2, "pqr"), (3, "xyz")] >>> m1`isPrefixOf`m2True
>>> m1 =fromList[(1, "abc"), (2, "p" ), (3, "x" )] >>> m2 =fromList[(1, "a" ), (2, "pqr"), (3, "xyz")] >>> m1`isPrefixOf`m2False
>>> m1 =fromList[("a", 1), ("b", 1), ("c", 1)] >>> m2 =fromList[("a", 2), ("b", 4), ("c", 8)] >>> m1`isPrefixOf`m2True
>>> m1 =fromList[ ("b", 1) ] >>> m2 =fromList[("a", 2), ("b", 4), ("c", 8)] >>> m1`isPrefixOf`m2True
>>> m1 =fromList[("a", 2), ("b", 1), ("c", 1)] >>> m2 =fromList[("a", 1), ("b", 4), ("c", 8)] >>> m1`isPrefixOf`m2False
stripPrefix :: (Ord k, MonoidNull v, LeftReductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v) Source #
Strips a prefix from a MonoidMap.
If map m1 is a prefix of map m2, then stripPrefix m1
 m2 will produce a reduced map where prefix m1 is stripped
 from m2.
Properties
The stripPrefix function, when applied to maps m1 and m2,
 produces a result if (and only if) m1 is a prefix of m2:
isJust(stripPrefixm1 m2)==m1`isPrefixOf`m2
The value for any key k in the result is identical to the result of
 stripping the value for k in map m1 from the value for k
 in map m2:
all(\r ->Just(getk r)==stripPrefix(getk m1) (getk m2)) (stripPrefixm1 m2)
If we append prefix m1 to the left-hand side of the result, we can
 always recover the original map m2:
all(\r -> m1<>r==m2) (stripPrefixm1 m2)
This function provides the definition of stripPrefix for the MonoidMap
 instance of LeftReductive.
Examples
With String values:
>>> m1 =fromList[(1, "" ), (2, "i" ), (3, "pq" ), (4, "xyz")] >>> m2 =fromList[(1, "abc"), (2, "ijk"), (3, "pqr"), (4, "xyz")] >>> m3 =fromList[(1, "abc"), (2, "jk"), (3, "r"), (4, "")]
>>>stripPrefixm1 m2==Justm3True
>>>stripPrefixm2 m1==NothingTrue
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 3), ("b", 3), ("c", 3), ("d", 3)] >>> m3 =fromList[("a", 3), ("b", 2), ("c", 1), ("d", 0)]
>>>stripPrefixm1 m2==Justm3True
>>>stripPrefixm2 m1==NothingTrue
commonPrefix :: (Ord k, MonoidNull v, LeftGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Finds the greatest common prefix of two maps.
Satisfies the following property for all possible keys k:
getk (commonPrefixm1 m2)==commonPrefix(getk m1) (getk m2)
This function provides the definition of commonPrefix for the
 MonoidMap instance of LeftGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1, "+++"), (2, "b++"), (3, "cc+"), (4, "ddd")] >>> m2 =fromList[(1, "---"), (2, "b--"), (3, "cc-"), (4, "ddd")] >>> m3 =fromList[(1, "" ), (2, "b" ), (3, "cc" ), (4, "ddd")]
>>>commonPrefixm1 m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 2), ("b", 2), ("c", 2), ("d", 2)] >>> m3 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 2)]
>>>commonPrefixm1 m2==m3True
stripCommonPrefix :: (Ord k, MonoidNull v, LeftGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v) Source #
Strips the greatest common prefix from a pair of maps.
Given two maps m1 and m2, stripCommonPrefix produces a
 tuple (p, r1, r2), where:
- pis the greatest common prefix of- m1and- m2
- r1is the remainder of stripping prefix- pfrom- m1
- r2is the remainder of stripping prefix- pfrom- m2
The resulting prefix p can be appended to the left-hand side of
 either remainder r1 or r2 to reproduce either of the original
 maps m1 or m2 respectively:
stripCommonPrefixm1 m2&\(p, r1, _) -> p<>r1==m1stripCommonPrefixm1 m2&\(p, _, r2) -> p<>r2==m2
Prefix p is identical to the result of applying commonPrefix to
 m1 and m2:
stripCommonPrefixm1 m2&\(p, _, _) -> p==commonPrefixm1 m2
Remainders r1 and r2 are identical to the results of applying
 stripPrefix to p and m1 or to p and m2
 respectively:
stripCommonPrefixm1 m2&\(p, r1, _) ->Justr1==stripPrefixp m1stripCommonPrefixm1 m2&\(p, _, r2) ->Justr2==stripPrefixp m2
This function provides the definition of stripCommonPrefix for the
 MonoidMap instance of LeftGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1, "+++"), (2, "a++"), (3, "aa+"), (4, "aaa")] >>> m2 =fromList[(1, "---"), (2, "a--"), (3, "aa-"), (4, "aaa")]
>>> p =fromList[(1, "" ), (2, "a" ), (3, "aa" ), (4, "aaa")] >>> r1 =fromList[(1, "+++"), (2, "++"), (3, "+"), (4, "")] >>> r2 =fromList[(1, "---"), (2, "--"), (3, "-"), (4, "")]
>>>stripCommonPrefixm1 m2==(p, r1, r2)True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)] >>> m2 =fromList[("a", 4), ("b", 3), ("c", 2), ("d", 1), ("e", 0)]
>>> p =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 1), ("e", 0)] >>> r1 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 2), ("e", 4)] >>> r2 =fromList[("a", 4), ("b", 2), ("c", 0), ("d", 0), ("e", 0)]
>>>stripCommonPrefixm1 m2==(p, r1, r2)True
Suffixes
isSuffixOf :: (Ord k, Monoid v, RightReductive v) => MonoidMap k v -> MonoidMap k v -> Bool Source #
Indicates whether or not the first map is a suffix of the second.
MonoidMap m1 is a suffix of MonoidMap m2 if (and only if)
 for all possible keys k, the value for k in m1 is a
 suffix of the value for k in m2:
m1`isSuffixOf`m2==(∀ k.getk m1`isSuffixOf`getk m2)
This function provides the definition of isSuffixOf for the MonoidMap
 instance of RightReductive.
Examples
With String values:
>>> m1 =fromList[(1, "c"), (2, "r"), (3, "z")] >>> m2 =fromList[(1, "abc"), (2, "pqr"), (3, "xyz")] >>> m1`isSuffixOf`m2True
>>> m1 =fromList[ (2, "r") ] >>> m2 =fromList[(1, "abc"), (2, "pqr"), (3, "xyz")] >>> m1`isSuffixOf`m2True
>>> m1 =fromList[(1, "abc"), (2, "r"), (3, "z")] >>> m2 =fromList[(1, "c"), (2, "pqr"), (3, "xyz")] >>> m1`isSuffixOf`m2False
>>> m1 =fromList[("a", 1), ("b", 1), ("c", 1)] >>> m2 =fromList[("a", 2), ("b", 4), ("c", 8)] >>> m1`isSuffixOf`m2True
>>> m1 =fromList[ ("b", 1) ] >>> m2 =fromList[("a", 2), ("b", 4), ("c", 8)] >>> m1`isSuffixOf`m2True
>>> m1 =fromList[("a", 2), ("b", 1), ("c", 1)] >>> m2 =fromList[("a", 1), ("b", 4), ("c", 8)] >>> m1`isSuffixOf`m2False
stripSuffix :: (Ord k, MonoidNull v, RightReductive v) => MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v) Source #
Strips a suffix from a MonoidMap.
If map m1 is a suffix of map m2, then stripSuffix m1
 m2 will produce a reduced map where suffix m1 is stripped
 from m2.
Properties
The stripSuffix function, when applied to maps m1 and m2,
 produces a result if (and only if) m1 is a suffix of m2:
isJust(stripSuffixm1 m2)==m1`isSuffixOf`m2
The value for any key k in the result is identical to the result of
 stripping the value for k in map m1 from the value for k
 in map m2:
all(\r ->Just(getk r)==stripSuffix(getk m1) (getk m2)) (stripSuffixm1 m2)
If we append suffix m1 to the right-hand side of the result, we can
 always recover the original map m2:
all(\r -> r<>m1==m2) (stripSuffixm1 m2)
This function provides the definition of stripSuffix for the MonoidMap
 instance of RightReductive.
Examples
With String values:
>>> m1 =fromList[(1, ""), (2, "k"), (3, "qr"), (4, "xyz")] >>> m2 =fromList[(1, "abc"), (2, "ijk"), (3, "pqr"), (4, "xyz")] >>> m3 =fromList[(1, "abc"), (2, "ij" ), (3, "p" ), (4, "" )]
>>>stripSuffixm1 m2==Justm3True
>>>stripSuffixm2 m1==NothingTrue
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 3), ("b", 3), ("c", 3), ("d", 3)] >>> m3 =fromList[("a", 3), ("b", 2), ("c", 1), ("d", 0)]
>>>stripSuffixm1 m2==Justm3True
>>>stripSuffixm2 m1==NothingTrue
commonSuffix :: (Ord k, MonoidNull v, RightGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Finds the greatest common suffix of two maps.
Satisfies the following property for all possible keys k:
getk (commonSuffixm1 m2)==commonSuffix(getk m1) (getk m2)
This function provides the definition of commonSuffix for the
 MonoidMap instance of RightGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1, "+++"), (2, "++b"), (3, "+cc"), (4, "ddd")] >>> m2 =fromList[(1, "---"), (2, "--b"), (3, "-cc"), (4, "ddd")] >>> m3 =fromList[(1, ""), (2, "b"), (3, "cc"), (4, "ddd")]
>>>commonSuffixm1 m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3)] >>> m2 =fromList[("a", 2), ("b", 2), ("c", 2), ("d", 2)] >>> m3 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 2)]
>>>commonSuffixm1 m2==m3True
stripCommonSuffix :: (Ord k, MonoidNull v, RightGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v) Source #
Strips the greatest common suffix from a pair of maps.
Given two maps m1 and m2, stripCommonSuffix produces a
 tuple (r1, r2, s), where:
- sis the greatest common suffix of- m1and- m2
- r1is the remainder of stripping suffix- sfrom- m1
- r2is the remainder of stripping suffix- sfrom- m2
The resulting suffix s can be appended to the right-hand side of
 either remainder r1 or r2 to reproduce either of the original
 maps m1 or m2 respectively:
stripCommonSuffixm1 m2&\(r1, _, s) -> r1<>s==m1stripCommonSuffixm1 m2&\(_, r2, s) -> r2<>s==m2
Suffix s is identical to the result of applying commonSuffix to
 m1 and m2:
stripCommonSuffixm1 m2&\(_, _, s) -> s==commonSuffixm1 m2
Remainders r1 and r2 are identical to the results of applying
 stripSuffix to s and m1 or to s and m2
 respectively:
stripCommonSuffixm1 m2&\(r1, _, s) ->Justr1==stripSuffixs m1stripCommonSuffixm1 m2&\(_, r2, s) ->Justr2==stripSuffixs m2
This function provides the definition of stripCommonSuffix for the
 MonoidMap instance of RightGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1, "+++"), (2, "++a"), (3, "+aa"), (4, "aaa")] >>> m2 =fromList[(1, "---"), (2, "--a"), (3, "-aa"), (4, "aaa")]
>>> r1 =fromList[(1, "+++"), (2, "++" ), (3, "+" ), (4, "" )] >>> r2 =fromList[(1, "---"), (2, "--" ), (3, "-" ), (4, "" )] >>> s =fromList[(1, ""), (2, "a"), (3, "aa"), (4, "aaa")]
>>>stripCommonSuffixm1 m2==(r1, r2, s)True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)] >>> m2 =fromList[("a", 4), ("b", 3), ("c", 2), ("d", 1), ("e", 0)]
>>> r1 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 2), ("e", 4)] >>> r2 =fromList[("a", 4), ("b", 2), ("c", 0), ("d", 0), ("e", 0)] >>> s =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 1), ("e", 0)]
>>>stripCommonSuffixm1 m2==(r1, r2, s)True
Overlap
overlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Finds the greatest overlap of two maps.
The greatest overlap o of maps m1 and m2 is the unique
 greatest map that is both a suffix of m1 and a prefix of m2:
m1==r1<>o m2==o<>r2
Where:
- r1is the remainder obtained by stripping suffix overlap- ofrom- m1.- (see - stripSuffixOverlap)
- r2is the remainder obtained by stripping prefix overlap- ofrom- m2.- (see - stripPrefixOverlap)
This function satisfies the following property:
getk (overlapm1 m2)==overlap(getk m1) (getk m2)
This function provides the definition of overlap for the MonoidMap
 instance of OverlappingGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1,"abc" ), (2,"abcd" ), (3,"abcde "), (4,"abcdef")] >>> m2 =fromList[(1, "def"), (2, "cdef"), (3," bcdef"), (4,"abcdef")] >>> m3 =fromList[(1, "" ), (2, "cd" ), (3," bcde" ), (4,"abcdef")]
>>>overlapm1 m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)] >>> m2 =fromList[("a", 4), ("b", 3), ("c", 2), ("d", 1), ("e", 0)] >>> m3 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 1), ("e", 0)]
>>>overlapm1 m2==m3True
stripPrefixOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Strips from the second map its greatest prefix overlap with suffixes of the first map.
Evaluating stripPrefixOverlap m1 m2 produces the remainder
 r2:
m1==r1<>o m2==o<>r2
Where o is the greatest overlap of maps m1 and m2: the
 unique greatest map that is both a suffix of m1 and a prefix of
 m2.
This function satisfies the following property:
getk (stripPrefixOverlapm1 m2)==stripPrefixOverlap(getk m1) (getk m2)
This function provides the definition of stripPrefixOverlap for the
 MonoidMap instance of OverlappingGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1,"abc" ), (2,"abcd" ), (3,"abcde" ), (4,"abcdef")] >>> m2 =fromList[(1, "def"), (2, "cdef"), (3, "bcdef"), (4,"abcdef")] >>> m3 =fromList[(1, "def"), (2, "ef"), (3, "f"), (4, "")]
>>>stripPrefixOverlapm1 m2==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)] >>> m2 =fromList[("a", 4), ("b", 3), ("c", 2), ("d", 1), ("e", 0)] >>> m3 =fromList[("a", 4), ("b", 2), ("c", 0), ("d", 0), ("e", 0)]
>>>stripPrefixOverlapm1 m2==m3True
stripSuffixOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v Source #
Strips from the second map its greatest suffix overlap with prefixes of the first map.
Evaluating stripSuffixOverlap m2 m1 produces the remainder
 r1:
m1==r1<>o m2==o<>r2
Where o is the greatest overlap of maps m1 and m2: the
 unique greatest map that is both a suffix of m1 and a prefix of
 m2.
This function satisfies the following property:
getk (stripSuffixOverlapm2 m1)==stripSuffixOverlap(getk m2) (getk m1)
This function provides the definition of stripSuffixOverlap for the
 MonoidMap instance of OverlappingGCDMonoid.
Examples
With String values:
>>> m1 =fromList[(1,"abc" ), (2,"abcd" ), (3,"abcde" ), (4,"abcdef")] >>> m2 =fromList[(1, "def"), (2, "cdef"), (3, "bcdef"), (4,"abcdef")] >>> m3 =fromList[(1,"abc" ), (2,"ab" ), (3,"a" ), (4,"" )]
>>>stripSuffixOverlapm2 m1==m3True
>>> m1 =fromList[("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)] >>> m2 =fromList[("a", 4), ("b", 3), ("c", 2), ("d", 1), ("e", 0)] >>> m3 =fromList[("a", 0), ("b", 0), ("c", 0), ("d", 2), ("e", 4)]
>>>stripSuffixOverlapm2 m1==m3True
stripOverlap :: (Ord k, MonoidNull v, OverlappingGCDMonoid v) => MonoidMap k v -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v) Source #
Finds the greatest overlap of two maps and strips it from both maps.
Evaluating stripOverlap m1 m2 produces the tuple
 (r1, o, r2), where:
m1==r1<>o m2==o<>r2
Where:
- ois the greatest overlap of maps- m1and- m2: the unique greatest map that is both a suffix of- m1and a prefix of- m2.- (see - overlap)
- r1is the remainder obtained by stripping suffix overlap- ofrom- m1.- (see - stripSuffixOverlap)
- r2is the remainder obtained by stripping prefix overlap- ofrom- m2.- (see - stripPrefixOverlap)
This function satisfies the following property:
stripOverlapm1 m2==(stripSuffixOverlapm2 m1 ,overlapm1 m2 ,stripPrefixOverlapm1 m2 )
This function provides the definition of stripOverlap for the
 MonoidMap instance of OverlappingGCDMonoid.