cardano-data-1.2.3.1: Specialized data for Cardano project
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

data StrictTriple a b c Source #

Constructors

StrictTriple !a !b !c 

Instances

Instances details
(Show a, Show b, Show c) ⇒ Show (StrictTriple a b c) Source # 
Instance details

Defined in Data.MapExtras

Methods

showsPrecIntStrictTriple a b c → ShowS Source #

showStrictTriple a b c → String Source #

showList ∷ [StrictTriple a b c] → ShowS Source #

(Eq a, Eq b, Eq c) ⇒ Eq (StrictTriple a b c) Source # 
Instance details

Defined in Data.MapExtras

Methods

(==)StrictTriple a b c → StrictTriple a b c → Bool Source #

(/=)StrictTriple a b c → StrictTriple a b c → Bool Source #

extractOrd 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.

noKeysOrd k ⇒ Map k a → Map k b → Map k a Source #

keysEqualOrd k ⇒ Map k v1 → Map k v2 → Bool Source #

splitMemberMapOrd 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

splitMemberSetOrd 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.

intersectDomPOrd 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)

intersectDomPLeftOrd 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.

intersectMapSetFoldOrd k ⇒ (k → v → ans → ans) → Map k v → Set k → ans → ans Source #

  • fold over the intersection of a Map and a Set

disjointMapSetFoldOrd 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.

extractKeysOrd 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)

extractKeysSmallSetOrd 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#

fromKeys ∷ (Foldable f, Ord k) ⇒ (k → v) → f k → Map k v Source #

Convert any foldable data structure with keys to a Map. Implemented in terms of fromList, therefore last duplicate key wins.

fromElems Source #

Arguments

∷ (Foldable f, Ord k) 
⇒ (v → k)

Function that will create a key from a value. Most common case is a hashing function.

→ f v 
Map k v 

Convert any foldable data structure with values to a Map. Implemented in terms of fromList, therefore last duplicate key wins.