Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A map represented as an "association list" of key-value pairs.
Synopsis
- data Map k v
- singleton ∷ k → v → Map k v
- empty ∷ Map k v
- null ∷ Map k v → Bool
- unsafeFromList ∷ [(k, v)] → Map k v
- safeFromList ∷ Eq k ⇒ [(k, v)] → Map k v
- toList ∷ Map k v → [(k, v)]
- keys ∷ Map k v → [k]
- elems ∷ Map k v → [v]
- lookup ∷ ∀ k v. Eq k ⇒ k → Map k v → Maybe v
- member ∷ ∀ k v. Eq k ⇒ k → Map k v → Bool
- insert ∷ ∀ k v. Eq k ⇒ k → v → Map k v → Map k v
- delete ∷ ∀ k v. Eq k ⇒ k → Map k v → Map k v
- union ∷ ∀ k v r. Eq k ⇒ Map k v → Map k r → Map k (These v r)
- unionWith ∷ ∀ k a. Eq k ⇒ (a → a → a) → Map k a → Map k a → Map k a
- filter ∷ (v → Bool) → Map k v → Map k v
- mapWithKey ∷ (k → a → b) → Map k a → Map k b
- mapMaybe ∷ (a → Maybe b) → Map k a → Map k b
- mapMaybeWithKey ∷ (k → a → Maybe b) → Map k a → Map k b
- all ∷ (a → Bool) → Map k a → Bool
- mapThese ∷ (v → These a b) → Map k v → (Map k a, Map k b)
Documentation
A Map
of key-value pairs.
A Map
is considered well-defined if there are no key collisions, meaning that each value
is uniquely identified by a key.
Use safeFromList
to create well-defined Map
s from arbitrary lists of pairs.
If cost minimisation is required, then you can use unsafeFromList
but you must
be certain that the list you are converting to a Map
abides by the well-definedness condition.
Most operations on Map
s are definedness-preserving, meaning that for the resulting Map
to be
well-defined then the input Map
(s) have to also be well-defined. This is not checked explicitly
unless mentioned in the documentation.
Take care when using fromBuiltinData
and unsafeFromBuiltinData
, as neither function performs
deduplication of the input collection and may create invalid Map
s!
Instances
Lift DefaultUni [(k, v)] ⇒ Lift DefaultUni (Map k v) Source # | |
Defined in PlutusTx.AssocMap lift ∷ Map k v → RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) Source # | |
(Lift k, Lift v) ⇒ Lift (Map k v ∷ Type) Source # | |
Foldable (Map k) Source # | |
Defined in PlutusTx.AssocMap | |
Functor (Map k) Source # | |
Traversable (Map k) Source # | |
Defined in PlutusTx.AssocMap | |
(Data k, Data v) ⇒ Data (Map k v) Source # | |
Defined in PlutusTx.AssocMap gfoldl ∷ (∀ d b. Data d ⇒ c (d → b) → d → c b) → (∀ g. g → c g) → Map k v → c (Map k v) Source # gunfold ∷ (∀ b r. Data b ⇒ c (b → r) → c r) → (∀ r. r → c r) → Constr → c (Map k v) Source # toConstr ∷ Map k v → Constr Source # dataTypeOf ∷ Map k v → DataType Source # dataCast1 ∷ Typeable t ⇒ (∀ d. Data d ⇒ c (t d)) → Maybe (c (Map k v)) Source # dataCast2 ∷ Typeable t ⇒ (∀ d e. (Data d, Data e) ⇒ c (t d e)) → Maybe (c (Map k v)) Source # gmapT ∷ (∀ b. Data b ⇒ b → b) → Map k v → Map k v Source # gmapQl ∷ (r → r' → r) → r → (∀ d. Data d ⇒ d → r') → Map k v → r Source # gmapQr ∷ ∀ r r'. (r' → r → r) → r → (∀ d. Data d ⇒ d → r') → Map k v → r Source # gmapQ ∷ (∀ d. Data d ⇒ d → u) → Map k v → [u] Source # gmapQi ∷ Int → (∀ d. Data d ⇒ d → u) → Map k v → u Source # gmapM ∷ Monad m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source # gmapMp ∷ MonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source # gmapMo ∷ MonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source # | |
Generic (Map k v) Source # | |
(Show k, Show v) ⇒ Show (Map k v) Source # | |
(NFData k, NFData v) ⇒ NFData (Map k v) Source # | |
Defined in PlutusTx.AssocMap | |
(Ord k, Eq v) ⇒ Eq (Map k v) Source # | |
(Ord k, Ord v) ⇒ Ord (Map k v) Source # | |
Defined in PlutusTx.AssocMap | |
(HasBlueprintDefinition k, HasBlueprintDefinition v) ⇒ HasBlueprintDefinition (Map k v) Source # | |
Defined in PlutusTx.AssocMap | |
(FromData k, FromData v) ⇒ FromData (Map k v) Source # | A hand-written transformation from |
Defined in PlutusTx.AssocMap fromBuiltinData ∷ BuiltinData → Maybe (Map k v) Source # | |
(ToData k, ToData v) ⇒ ToData (Map k v) Source # | Hand-written instances to use the underlying |
Defined in PlutusTx.AssocMap toBuiltinData ∷ Map k v → BuiltinData Source # | |
(UnsafeFromData k, UnsafeFromData v) ⇒ UnsafeFromData (Map k v) Source # | A hand-written transformation from |
Defined in PlutusTx.AssocMap unsafeFromBuiltinData ∷ BuiltinData → Map k v Source # | |
(Eq k, Semigroup v) ⇒ Monoid (Map k v) Source # | |
Defined in PlutusTx.AssocMap | |
(Eq k, Semigroup v) ⇒ Semigroup (Map k v) Source # | |
(Pretty k, Pretty v) ⇒ Pretty (Map k v) Source # | |
(HasBlueprintSchema k referencedTypes, HasBlueprintSchema v referencedTypes) ⇒ HasBlueprintSchema (Map k v) referencedTypes Source # | |
Defined in PlutusTx.AssocMap | |
Typeable DefaultUni Map Source # | |
Defined in PlutusTx.AssocMap typeRep ∷ Proxy Map → RTCompile DefaultUni fun (Type TyName DefaultUni ()) Source # | |
type Rep (Map k v) Source # | |
Defined in PlutusTx.AssocMap | |
type Unroll (Map k v) Source # | |
Defined in PlutusTx.AssocMap |
unsafeFromList ∷ [(k, v)] → Map k v Source #
Unsafely create a Map
from a list of pairs. This should _only_ be applied to lists which
have been checked to not contain duplicate keys, otherwise the resulting Map
will contain
conflicting entries (two entries sharing the same key).
As usual, the "keys" are considered to be the first element of the pair.
safeFromList ∷ Eq k ⇒ [(k, v)] → Map k v Source #
In case of duplicates, this function will keep only one entry (the one that precedes). In other words, this function de-duplicates the input list.
insert ∷ ∀ k v. Eq k ⇒ k → v → Map k v → Map k v Source #
If a key already exists in the map, its entry will be replaced with the new value.
union ∷ ∀ k v r. Eq k ⇒ Map k v → Map k r → Map k (These v r) Source #
Combine two Map
s. Keeps both values on key collisions.
Note that well-formedness is only preserved if the two input maps
are also well-formed.
Also, as an implementation detail, in the case that the right map contains
duplicate keys, and there exists a collision between the two maps,
then only the left-most value of the right map will be kept.
unionWith ∷ ∀ k a. Eq k ⇒ (a → a → a) → Map k a → Map k a → Map k a Source #
Combine two Map
s with the given combination function.
Note that well-formedness of the resulting map depends on the two input maps
being well-formed.
Also, as an implementation detail, in the case that the right map contains
duplicate keys, and there exists a collision between the two maps,
then only the left-most value of the right map will be kept.
mapWithKey ∷ (k → a → b) → Map k a → Map k b Source #
Map a function over all values in the map.
mapMaybeWithKey ∷ (k → a → Maybe b) → Map k a → Map k b Source #
Map keys/values and collect the Just
results.