Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Map k a
- lookup ∷ ∀ k a. (ToData k, UnsafeFromData a) ⇒ k → Map k a → Maybe a
- member ∷ ∀ k a. ToData k ⇒ k → Map k a → Bool
- insert ∷ ∀ k a. (ToData k, ToData a) ⇒ k → a → Map k a → Map k a
- delete ∷ ∀ k a. ToData k ⇒ k → Map k a → Map k a
- singleton ∷ ∀ k a. (ToData k, ToData a) ⇒ k → a → Map k a
- empty ∷ ∀ k a. Map k a
- null ∷ ∀ k a. Map k a → Bool
- toList ∷ (UnsafeFromData k, UnsafeFromData a) ⇒ Map k a → [(k, a)]
- toBuiltinList ∷ Map k a → BuiltinList (BuiltinPair BuiltinData BuiltinData)
- safeFromList ∷ ∀ k a. (ToData k, ToData a) ⇒ [(k, a)] → Map k a
- unsafeFromList ∷ (ToData k, ToData a) ⇒ [(k, a)] → Map k a
- unsafeFromBuiltinList ∷ ∀ k a. BuiltinList (BuiltinPair BuiltinData BuiltinData) → Map k a
- noDuplicateKeys ∷ ∀ k a. Map k a → Bool
- all ∷ ∀ k a. UnsafeFromData a ⇒ (a → Bool) → Map k a → Bool
- any ∷ ∀ k a. UnsafeFromData a ⇒ (a → Bool) → Map k a → Bool
- union ∷ ∀ k a b. (UnsafeFromData a, UnsafeFromData b, ToData a, ToData b) ⇒ Map k a → Map k b → Map k (These a b)
- unionWith ∷ ∀ k a. (UnsafeFromData a, ToData a) ⇒ (a → a → a) → Map k a → Map k a → Map k a
- keys ∷ ∀ k a. Map k a → BuiltinList BuiltinData
- map ∷ ∀ k a b. (UnsafeFromData a, ToData b) ⇒ (a → b) → Map k a → Map k b
- mapThese ∷ ∀ v k a b. (ToData a, ToData b, UnsafeFromData v) ⇒ (v → These a b) → Map k v → (Map k a, Map k b)
- foldr ∷ ∀ a b k. UnsafeFromData a ⇒ (a → b → b) → b → Map k a → b
Documentation
A map associating keys and values backed by BuiltinData
.
This implementation has the following characteristics:
- The
toBuiltinData
andunsafeFromBuiltinData
operations are no-op. - Other operations are slower than
PlutusTx.AssocMap.Map
, although equality checks on keys can be faster due toequalsData
. - Many operations involve converting the keys and/or values to/from
BuiltinData
.
Therefore this implementation is likely a better choice than PlutusTx.AssocMap.Map
if it is part of a data type defined using asData
, and the key and value types
have efficient toBuiltinData
and unsafeFromBuiltinData
operations (e.g., they
are primitive types or types defined using asData
).
A Map
is considered well-defined if it has no duplicate keys. Most operations
preserve the definedness of the resulting Map
unless otherwise noted.
It is important to observe that, in comparison to standard map implementations,
this implementation provides slow lookup and update operations because it is based
on a list representation.
Instances
Lift DefaultUni (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap lift ∷ Map k a → RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) Source # | |
Show (Map k a) Source # | |
FromData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap fromBuiltinData ∷ BuiltinData → Maybe (Map k a) Source # | |
ToData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap toBuiltinData ∷ Map k a → BuiltinData Source # | |
UnsafeFromData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap unsafeFromBuiltinData ∷ BuiltinData → Map k a Source # | |
(Pretty k, Pretty a, UnsafeFromData k, UnsafeFromData a) ⇒ Pretty (Map k a) Source # | |
Typeable DefaultUni Map Source # | |
Defined in PlutusTx.Data.AssocMap typeRep ∷ Proxy Map → RTCompile DefaultUni fun (Type TyName DefaultUni ()) Source # |
lookup ∷ ∀ k a. (ToData k, UnsafeFromData a) ⇒ k → Map k a → Maybe a Source #
Look up the value corresponding to the key.
If the Map
is not well-defined, the result is the value associated with
the left-most occurrence of the key in the list.
This operation is O(n).
insert ∷ ∀ k a. (ToData k, ToData a) ⇒ k → a → Map k a → Map k a Source #
Insert a key-value pair into the Map
. If the key is already present,
the value is updated.
singleton ∷ ∀ k a. (ToData k, ToData a) ⇒ k → a → Map k a Source #
Create an Map
with a single key-value pair.
toList ∷ (UnsafeFromData k, UnsafeFromData a) ⇒ Map k a → [(k, a)] Source #
Convert the Map
to a list of key-value pairs. This operation is O(n).
See toBuiltinList
for a more efficient alternative.
toBuiltinList ∷ Map k a → BuiltinList (BuiltinPair BuiltinData BuiltinData) Source #
Convert the Map
to a BuiltinList
of key-value pairs. This operation is O(1).
safeFromList ∷ ∀ k a. (ToData k, ToData a) ⇒ [(k, a)] → Map k a Source #
Create an Map
from a list of key-value pairs.
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.
unsafeFromBuiltinList ∷ ∀ k a. BuiltinList (BuiltinPair BuiltinData BuiltinData) → Map k a Source #
Unsafely create an Map
from a BuiltinList
of key-value pairs.
This function is unsafe because it assumes that the elements of the list can be safely
decoded from their BuiltinData
representation.
noDuplicateKeys ∷ ∀ k a. Map k a → Bool Source #
Check if the Map
is well-defined. Warning: this operation is O(n^2).
any ∷ ∀ k a. UnsafeFromData a ⇒ (a → Bool) → Map k a → Bool Source #
Check if any value in the Map
satisfies the predicate.
union ∷ ∀ k a b. (UnsafeFromData a, UnsafeFromData b, ToData a, ToData b) ⇒ Map k a → Map k b → Map k (These a b) Source #
Combine two Map
s into one. It saves both values if the key is present in both maps.
unionWith ∷ ∀ k a. (UnsafeFromData a, ToData a) ⇒ (a → a → a) → Map k a → Map k a → Map k a Source #
Combine two Map
s with the given combination function.
keys ∷ ∀ k a. Map k a → BuiltinList BuiltinData Source #
mapThese ∷ ∀ v k a b. (ToData a, ToData b, UnsafeFromData v) ⇒ (v → These a b) → Map k v → (Map k a, Map k b) Source #
foldr ∷ ∀ a b k. UnsafeFromData a ⇒ (a → b → b) → b → Map k a → b Source #