plutus-tx-1.30.0.0: Libraries for Plutus Tx and its prelude
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusTx.Data.AssocMap

Synopsis

Documentation

data Map k a Source #

A map associating keys and values backed by BuiltinData.

This implementation has the following characteristics:

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

Instances details
Lift DefaultUni (Map k a) Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

Methods

liftMap k a → RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) Source #

Show (Map k a) Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

Methods

showsPrecIntMap k a → ShowS Source #

showMap k a → String Source #

showList ∷ [Map k a] → ShowS Source #

FromData (Map k a) Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

ToData (Map k a) Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

Methods

toBuiltinDataMap k a → BuiltinData Source #

UnsafeFromData (Map k a) Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

Typeable DefaultUni Map Source # 
Instance details

Defined in PlutusTx.Data.AssocMap

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

member ∷ ∀ k a. ToData k ⇒ k → Map k a → Bool Source #

Check if the key is in the Map.

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.

delete ∷ ∀ k a. ToData k ⇒ k → Map k a → Map k a Source #

Delete a key value pair from the Map. If the Map is not well-defined, it deletes the pair associated with the left-most occurrence of the key in the list.

singleton ∷ ∀ k a. (ToData k, ToData a) ⇒ k → a → Map k a Source #

Create an Map with a single key-value pair.

empty ∷ ∀ k a. Map k a Source #

An empty Map.

null ∷ ∀ k a. Map k a → Bool Source #

Check if the Map is empty.

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.

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

unsafeFromList ∷ (ToData k, ToData a) ⇒ [(k, a)] → Map k a Source #

Unsafely create an 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), and therefore be ill-defined.

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

all ∷ ∀ k a. UnsafeFromData a ⇒ (a → Bool) → Map k a → Bool Source #

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.

keys ∷ ∀ k a. Map k a → BuiltinList BuiltinData Source #

map ∷ ∀ k a b. (UnsafeFromData a, ToData b) ⇒ (a → b) → Map k a → Map k b 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 #