| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusTx.Data.AssocMap
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
- toSOPList ∷ (UnsafeFromData k, UnsafeFromData a) ⇒ Map k a → [(k, a)]
- toBuiltinList ∷ Map k a → BuiltinList (BuiltinPair BuiltinData BuiltinData)
- safeFromSOPList ∷ ∀ k a. (ToData k, ToData a) ⇒ [(k, a)] → Map k a
- unsafeFromSOPList ∷ (ToData k, ToData a) ⇒ [(k, a)] → Map k a
- unsafeFromDataList ∷ List (a, k) → 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 → List k
- elems ∷ ∀ k a. Map k a → List a
- 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
- filter ∷ ∀ k a. UnsafeFromData a ⇒ (a → Bool) → Map k a → Map k a
- mapWithKey ∷ ∀ k a b. (UnsafeFromData k, UnsafeFromData a, ToData b) ⇒ (k → a → b) → Map k a → Map k b
- mapMaybe ∷ ∀ k a b. (UnsafeFromData a, ToData b) ⇒ (a → Maybe b) → Map k a → Map k b
- mapMaybeWithKey ∷ ∀ k a b. (UnsafeFromData k, UnsafeFromData a, ToData b) ⇒ (k → a → Maybe b) → Map k a → Map k b
Documentation
A map associating keys and values backed by BuiltinData.
This implementation has the following characteristics:
- The
toBuiltinDataandunsafeFromBuiltinDataoperations 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 Methods 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 Methods fromBuiltinData ∷ BuiltinData → Maybe (Map k a) Source # | |
| ToData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap Methods toBuiltinData ∷ Map k a → BuiltinData Source # | |
| UnsafeFromData (Map k a) Source # | |
Defined in PlutusTx.Data.AssocMap Methods 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 Methods 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.
toSOPList ∷ (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).
safeFromSOPList ∷ ∀ k a. (ToData k, ToData a) ⇒ [(k, a)] → Map k a Source #
Create an Map from a sums of products 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.
Warning: this function is very slow. If you know that the input list does not contain
duplicate keys, use one of the unsafe functions instead.
unsafeFromSOPList ∷ (ToData k, ToData a) ⇒ [(k, a)] → Map k a Source #
Unsafely create an Map from a sums of products 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), and therefore be ill-defined.
Warning: this requires traversing the list and encoding the keys and values, so it
should be avoided in favor of unsafeFromBuiltinList if the input is already in
BuiltinData form.
unsafeFromDataList ∷ List (a, k) → Map k a Source #
Unsafely create an Map from a List 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. It also does not deduplicate the keys.
unsafeFromBuiltinList ∷ ∀ k a. BuiltinList (BuiltinPair BuiltinData BuiltinData) → Map k a Source #
Unsafely create an Map from a BuiltinList of key-value pairs. This operation
is O(1).
This function is unsafe because it assumes that the elements of the list can be safely
decoded from their BuiltinData representation. It also does not deduplicate the keys.
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 Maps 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 Maps with the given combination function.
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 #
mapWithKey ∷ ∀ k a b. (UnsafeFromData k, UnsafeFromData a, ToData b) ⇒ (k → a → b) → Map k a → Map k b Source #
mapMaybeWithKey ∷ ∀ k a b. (UnsafeFromData k, UnsafeFromData a, ToData b) ⇒ (k → a → Maybe b) → Map k a → Map k b Source #