Hoogle Search
Within LTS Haskell 24.45 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
foldMapWithKey :: Semigroup m => (k -> a -> m) -> NEMap k a -> mnonempty-containers Data.Map.NonEmpty O(n). Fold the keys and values in the map using the given semigroup, such that
foldMapWithKey f = fold1 . mapWithKey f
This can be an asymptotically faster than foldrWithKey or foldlWithKey for some monoids.insertMap :: Ord k => k -> a -> Map k a -> NEMap k anonempty-containers Data.Map.NonEmpty O(log n). Convert a Map into an NEMap by adding a key-value pair. Because of this, we know that the map must have at least one element, and so therefore cannot be empty. If key is already present, will overwrite the original value. See insertMapMin for a version that is constant-time if the new key is strictly smaller than all keys in the original map.
insertMap 4 "c" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(4,"c"), (5,"a")]) insertMap 4 "c" Data.Map.empty == singleton 4 "c"
insertMapMax :: k -> a -> Map k a -> NEMap k anonempty-containers Data.Map.NonEmpty O(log n) Convert a Map into an NEMap by adding a key-value pair where the key is strictly greater than all keys in the input map. The keys in the original map must all be strictly less than the new key. The precondition is not checked. While this has the same asymptotics as insertMap, it saves a constant factor for key comparison (so may be helpful if comparison is expensive) and also does not require an Ord instance for the key type.
insertMap 7 "c" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(5,"a"), (7,"c")]) valid (insertMap 7 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == True valid (insertMap 2 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == False valid (insertMap 5 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == False
insertMapMin :: k -> a -> Map k a -> NEMap k anonempty-containers Data.Map.NonEmpty O(1) Convert a Map into an NEMap by adding a key-value pair where the key is strictly less than all keys in the input map. The keys in the original map must all be strictly greater than the new key. The precondition is not checked.
insertMapMin 2 "c" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((2,"c") :| [(3,"b"), (5,"a")]) valid (insertMapMin 2 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == True valid (insertMapMin 7 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == False valid (insertMapMin 3 "c" (Data.Map.fromList [(5,"a"), (3,"b")])) == False
insertMapWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> NEMap k anonempty-containers Data.Map.NonEmpty O(log n). Convert a Map into an NEMap by adding a key-value pair. Because of this, we know that the map must have at least one element, and so therefore cannot be empty. Uses a combining function with the new value as the first argument if the key is already present.
insertMapWith (++) 4 "c" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(4,"c"), (5,"a")]) insertMapWith (++) 5 "c" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3,"b") :| [(5,"ca")])
insertMapWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> NEMap k anonempty-containers Data.Map.NonEmpty O(log n). Convert a Map into an NEMap by adding a key-value pair. Because of this, we know that the map must have at least one element, and so therefore cannot be empty. Uses a combining function with the key and new value as the first and second arguments if the key is already present.
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value insertWithKey f 5 "xxx" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3, "b") :| [(5, "5:xxx|a")]) insertWithKey f 7 "xxx" (Data.Map.fromList [(5,"a"), (3,"b")]) == fromList ((3, "b") :| [(5, "a"), (7, "xxx")]) insertWithKey f 5 "xxx" Data.Map.empty == singleton 5 "xxx"
isProperSubmapOf :: (Ord k, Eq a) => NEMap k a -> NEMap k a -> Boolnonempty-containers Data.Map.NonEmpty O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal). Defined as (isProperSubmapOf = isProperSubmapOfBy (==)).
isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> NEMap k a -> NEMap k b -> Boolnonempty-containers Data.Map.NonEmpty O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal). The expression (isProperSubmapOfBy f m1 m2) returns True when m1 and m2 are not equal, all keys in m1 are in m2, and when f returns True when applied to their respective values. For example, the following expressions are all True:
isProperSubmapOfBy (==) (singleton 1 1) (fromList ((1,1) :| [(2,2)])) isProperSubmapOfBy (<=) (singleton 1 1) (fromList ((1,1) :| [(2,2)]))
But the following are all False:isProperSubmapOfBy (==) (fromList ((1,1) :| [(2,2)])) (fromList ((1,1) :| [(2,2)])) isProperSubmapOfBy (==) (fromList ((1,1) :| [(2,2)])) (singleton 1 1)) isProperSubmapOfBy (<) (singleton 1 1) (fromList ((1,1) :| [(2,2)]))
isSubmapOf :: (Ord k, Eq a) => NEMap k a -> NEMap k a -> Boolnonempty-containers Data.Map.NonEmpty O(m*log(n/m + 1)), m <= n. This function is defined as (isSubmapOf = isSubmapOfBy (==)).
isSubmapOfBy :: Ord k => (a -> b -> Bool) -> NEMap k a -> NEMap k b -> Boolnonempty-containers Data.Map.NonEmpty O(m*log(n/m + 1)), m <= n. The expression (isSubmapOfBy f t1 t2) returns True if all keys in t1 are in tree t2, and when f returns True when applied to their respective values. For example, the following expressions are all True:
isSubmapOfBy (==) (singleton 'a' 1) (fromList (('a',1) :| [('b',2)])) isSubmapOfBy (<=) (singleton 'a' 1) (fromList (('a',1) :| [('b',2)])) isSubmapOfBy (==) (fromList (('a',1) :| [('b',2)])) (fromList (('a',1) :| [('b',2)]))But the following are all False:isSubmapOfBy (==) (singleton 'a' 2) (fromList (('a',1) :| [('b',2)])) isSubmapOfBy (<) (singleton 'a' 1) (fromList (('a',1) :| [('b',2)])) isSubmapOfBy (==) (fromList (('a',1) :| [('b',2)])) (singleton 'a' 1)