cardano-data-0.1.0.0: Specialized data for Cardano project
Safe Haskell None
Language Haskell2010

Data.MapExtras

Description

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:

  1. Version of withoutKeys where both arguments are Map
  2. Comparing that two maps have exactly the same set of keys
  3. The intersection of two maps guarded by a predicate.
((dom stkcred) ◁ deleg) ▷ (dom stpool)) ==>
intersectDomP (\ k v -> Map.member v stpool) stkcred deleg
Synopsis

Documentation

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.

extractKeys :: Ord k => Map k a -> Set k -> ( Map k a, Map k a) Source #

Partition the Map according to keys in the Set . This is equivalent to:

extractKeys m s === (withoutKeys m s, restrictKeys m s)

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#