Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Sometimes we need to write our own version of functions over Map
that
do not appear in the "containers" library. This module is for such functions.
For example:
- Version of
withoutKeys
where both arguments areMap
- Comparing that two maps have exactly the same set of keys
- The intersection of two maps guarded by a predicate.
((dom stkcred) ◁ deleg) ▷ (dom stpool)) ==> intersectDomP (\ k v -> Map.member v stpool) stkcred deleg
Synopsis
- data StrictTriple a b c = StrictTriple !a !b !c
- extract ∷ Ord k ⇒ k → Map k b → (Maybe b, Map k b)
- noKeys ∷ Ord k ⇒ Map k a → Map k b → Map k a
- keysEqual ∷ Ord k ⇒ Map k v1 → Map k v2 → Bool
- splitMemberMap ∷ Ord k ⇒ k → Map k a → StrictTriple (Map k a) Bool (Map k a)
- splitMemberSet ∷ Ord a ⇒ a → Set a → StrictTriple (Set a) Bool (Set a)
- intersectDomP ∷ Ord k ⇒ (k → v2 → Bool) → Map k v1 → Map k v2 → Map k v2
- intersectDomPLeft ∷ Ord k ⇒ (k → v2 → Bool) → Map k v1 → Map k v2 → Map k v1
- intersectMapSetFold ∷ Ord k ⇒ (k → v → ans → ans) → Map k v → Set k → ans → ans
- disjointMapSetFold ∷ Ord k ⇒ (k → v → ans → ans) → Map k v → Set k → ans → ans
- extractKeys ∷ Ord k ⇒ Map k a → Set k → (Map k a, Map k a)
- extractKeysSmallSet ∷ Ord k ⇒ Map k a → Set k → (Map k a, Map k a)
- fromKeys ∷ (Foldable f, Ord k) ⇒ (k → v) → f k → Map k v
- fromElems ∷ (Foldable f, Ord k) ⇒ (v → k) → f v → Map k v
Documentation
data StrictTriple a b c Source #
StrictTriple !a !b !c |
Instances
(Show a, Show b, Show c) ⇒ Show (StrictTriple a b c) Source # | |
Defined in Data.MapExtras | |
(Eq a, Eq b, Eq c) ⇒ Eq (StrictTriple a b c) Source # | |
Defined in Data.MapExtras (==) ∷ StrictTriple a b c → StrictTriple a b c → Bool Source # (/=) ∷ StrictTriple a b c → StrictTriple a b c → Bool Source # |
extract ∷ Ord k ⇒ k → Map k b → (Maybe b, Map k b) Source #
Just like delete
, but also returns the value if it was indeed deleted
from the map.
splitMemberMap ∷ Ord k ⇒ k → Map k a → StrictTriple (Map k a) Bool (Map k a) Source #
A variant of splitLookup
that indicates only whether the
key was present, rather than producing its value. This is used to
implement keysEqual
to avoid allocating unnecessary Just
constructors.
Note - this is a copy pasted internal function from "containers" package
adjusted to return StrictTriple
splitMemberSet ∷ Ord a ⇒ a → Set a → StrictTriple (Set a) Bool (Set a) Source #
O(log n). Performs a split
but also returns whether the pivot
element was found in the original set.
This is a modified version of splitMember
, where StrictTriple
is used
instead of a lazy one for minor performance gain.
intersectDomP ∷ Ord k ⇒ (k → v2 → Bool) → Map k v1 → Map k v2 → Map k v2 Source #
intersetDomP p m1 m2 == Keep the key and value from m2, iff (the key is in the dom of m1) && ((p key value) is true)
intersectDomPLeft ∷ Ord k ⇒ (k → v2 → Bool) → Map k v1 → Map k v2 → Map k v1 Source #
- Similar to intersectDomP, except the Map returned has the same key as the first input map, rather than the second input map.
intersectMapSetFold ∷ Ord k ⇒ (k → v → ans → ans) → Map k v → Set k → ans → ans Source #
- fold over the intersection of a Map and a Set
disjointMapSetFold ∷ Ord k ⇒ (k → v → ans → ans) → Map k v → Set k → ans → ans Source #
Fold with accum
all those pairs in the map, not appearing in the set.
extractKeysSmallSet ∷ Ord k ⇒ Map k a → Set k → (Map k a, Map k a) Source #
It has been discovered expirementally through benchmarks that for small Set
size of under around 6 elements this function performs faster than
extractKeys#