Hoogle Search
Within LTS Haskell 24.40 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
neimIntMap :: NEIntMap a -> !IntMap anonempty-containers Data.IntMap.NonEmpty.Internal No documentation available.
nonEmptyMap :: IntMap a -> Maybe (NEIntMap a)nonempty-containers Data.IntMap.NonEmpty.Internal O(log n). Smart constructor for an NEIntMap from a IntMap. Returns Nothing if the IntMap was originally actually empty, and Just n with an NEIntMap, if the IntMap was not empty. nonEmptyMap and maybe empty toMap form an isomorphism: they are perfect structure-preserving inverses of eachother. See IsNonEmpty for a pattern synonym that lets you "match on" the possiblity of a IntMap being an NEIntMap.
nonEmptyMap (Data.IntMap.fromList [(3,"a"), (5,"b")]) == Just (fromList ((3,"a") :| [(5,"b")]))
toMap :: NEIntMap a -> IntMap anonempty-containers Data.IntMap.NonEmpty.Internal O(log n). Convert a non-empty map back into a normal possibly-empty map, for usage with functions that expect IntMap. Can be thought of as "obscuring" the non-emptiness of the map in its type. See the IsNotEmpty pattern. nonEmptyMap and maybe empty toMap form an isomorphism: they are perfect structure-preserving inverses of eachother.
toMap (fromList ((3,"a") :| [(5,"b")])) == Data.IntMap.fromList [(3,"a"), (5,"b")]
-
nonempty-containers Data.Map.NonEmpty A non-empty (by construction) map from keys k to values a. At least one key-value pair exists in an NEMap k v at all times. Functions that take an NEMap can safely operate on it with the assumption that it has at least one key-value pair. Functions that return an NEMap provide an assurance that the result has at least one key-value pair. Data.Map.NonEmpty re-exports the API of Data.Map, faithfully reproducing asymptotics, typeclass constraints, and semantics. Functions that ensure that input and output maps are both non-empty (like insert) return NEMap, but functions that might potentially return an empty map (like delete) return a Map instead. You can directly construct an NEMap with the API from Data.Map.NonEmpty; it's more or less the same as constructing a normal Map, except you don't have access to empty. There are also a few ways to construct an NEMap from a Map:
- The nonEmptyMap smart constructor will convert a Map k a into a Maybe (NEMap k a), returning Nothing if the original Map was empty.
- You can use the insertMap family of functions to insert a value into a Map to create a guaranteed NEMap.
- You can use the IsNonEmpty and IsEmpty patterns to "pattern match" on a Map to reveal it as either containing a NEMap or an empty map.
- withNonEmpty offers a continuation-based interface for deconstructing a Map and treating it as if it were an NEMap.
absurdNEMap :: NEMap Void a -> bnonempty-containers Data.Map.NonEmpty Special property of non-empty maps: The type of non-empty maps over uninhabited keys is itself uninhabited. This property also exists for values inside a non-empty container (like for NESet, NESeq, and NEIntMap); this can be witnessed using the function absurd . fold1.
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")])