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

PlutusTx.AssocMap

Description

A map represented as an "association list" of key-value pairs.

Synopsis

Documentation

data Map k v Source #

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 Maps 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 Maps 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 Maps!

Instances

Instances details
Lift DefaultUni [(k, v)] ⇒ Lift DefaultUni (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

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

(Lift k, Lift v) ⇒ Lift (Map k v ∷ Type) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

liftQuote m ⇒ Map k v → m Exp Source #

liftTyped ∷ ∀ (m ∷ TypeType). Quote m ⇒ Map k v → Code m (Map k v) Source #

Foldable (Map k) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

foldr ∷ (a → b → b) → b → Map k a → b Source #

Functor (Map k) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

fmap ∷ (a → b) → Map k a → Map k b Source #

Traversable (Map k) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

traverseApplicative f ⇒ (a → f b) → Map k a → f (Map k b) Source #

(Data k, Data v) ⇒ Data (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

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 #

toConstrMap k v → Constr Source #

dataTypeOfMap k v → DataType Source #

dataCast1Typeable t ⇒ (∀ d. Data d ⇒ c (t d)) → Maybe (c (Map k v)) Source #

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

gmapQiInt → (∀ d. Data d ⇒ d → u) → Map k v → u Source #

gmapMMonad m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source #

gmapMpMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source #

gmapMoMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → Map k v → m (Map k v) Source #

Generic (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Associated Types

type Rep (Map k v) ∷ TypeType Source #

Methods

fromMap k v → Rep (Map k v) x Source #

toRep (Map k v) x → Map k v Source #

(Show k, Show v) ⇒ Show (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

showsPrecIntMap k v → ShowS Source #

showMap k v → String Source #

showList ∷ [Map k v] → ShowS Source #

(NFData k, NFData v) ⇒ NFData (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

rnfMap k v → () Source #

(Ord k, Eq v) ⇒ Eq (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

(==)Map k v → Map k v → Bool Source #

(/=)Map k v → Map k v → Bool Source #

(Ord k, Ord v) ⇒ Ord (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

compareMap k v → Map k v → Ordering Source #

(<)Map k v → Map k v → Bool Source #

(<=)Map k v → Map k v → Bool Source #

(>)Map k v → Map k v → Bool Source #

(>=)Map k v → Map k v → Bool Source #

maxMap k v → Map k v → Map k v Source #

minMap k v → Map k v → Map k v Source #

(HasBlueprintDefinition k, HasBlueprintDefinition v) ⇒ HasBlueprintDefinition (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Associated Types

type Unroll (Map k v) ∷ [Type] Source #

(FromData k, FromData v) ⇒ FromData (Map k v) Source #

A hand-written transformation from Data to Map. Compared to unsafeFromBuiltinData, it is safe to call when it is unknown if the Data is built with Datas Map constructor. Note that it is, however, unsafe in the sense that it assumes that any map encoded in the Data is well-formed, i.e. fromBuiltinData does not perform any deduplication of keys or of key-value pairs!

Instance details

Defined in PlutusTx.AssocMap

(ToData k, ToData v) ⇒ ToData (Map k v) Source #

Hand-written instances to use the underlying Map type in Data, and to be reasonably efficient.

Instance details

Defined in PlutusTx.AssocMap

Methods

toBuiltinDataMap k v → BuiltinData Source #

(UnsafeFromData k, UnsafeFromData v) ⇒ UnsafeFromData (Map k v) Source #

A hand-written transformation from Data to Map. It is unsafe because the caller must provide the guarantee that the Data is constructed using the Datas Map constructor. Note that it assumes, like the fromBuiltinData transformation, that the map encoded in the Data is well-formed, i.e. unsafeFromBuiltinData does not perform any deduplication of keys or of key-value pairs!

Instance details

Defined in PlutusTx.AssocMap

(Eq k, Semigroup v) ⇒ Monoid (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

memptyMap k v Source #

(Eq k, Semigroup v) ⇒ Semigroup (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

(<>)Map k v → Map k v → Map k v Source #

(Pretty k, Pretty v) ⇒ Pretty (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

prettyMap k v → Doc ann Source #

prettyList ∷ [Map k v] → Doc ann Source #

(HasBlueprintSchema k referencedTypes, HasBlueprintSchema v referencedTypes) ⇒ HasBlueprintSchema (Map k v) referencedTypes Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

schemaSchema referencedTypes Source #

Typeable DefaultUni Map Source # 
Instance details

Defined in PlutusTx.AssocMap

type Rep (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

type Rep (Map k v) = D1 ('MetaData "Map" "PlutusTx.AssocMap" "plutus-tx-1.39.0.0-inplace" 'True) (C1 ('MetaCons "Map" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(k, v)])))
type Unroll (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

type Unroll (Map k v) = '[Map k v, k, v]

singleton ∷ k → v → Map k v Source #

A singleton map.

emptyMap k v Source #

An empty Map.

nullMap k v → Bool Source #

Is the map empty?

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.

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

toListMap k v → [(k, v)] Source #

keysMap k v → [k] Source #

The keys of a Map. Semantically, the resulting list is only a set if the Map didn't contain duplicate keys.

elemsMap k v → [v] Source #

Return all elements of the map.

lookup ∷ ∀ k v. Eq k ⇒ k → Map k v → Maybe v Source #

Find an entry in a Map. If the Map is not well-formed (it contains duplicate keys) then this will return the value of the left-most pair in the underlying list of pairs.

member ∷ ∀ k v. Eq k ⇒ k → Map k v → Bool Source #

Is the key a member of the map?

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.

delete ∷ ∀ k v. Eq k ⇒ k → Map k v → Map k v Source #

Delete an entry from the Map. Assumes that the Map is well-formed, i.e. if the underlying list of pairs contains pairs with duplicate keys then only the left-most pair will be removed.

union ∷ ∀ k v r. Eq k ⇒ Map k v → Map k r → Map k (These v r) Source #

Combine two Maps. 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 Maps 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.

filter ∷ (v → Bool) → Map k v → Map k v Source #

Filter all values that satisfy the predicate.

mapWithKey ∷ (k → a → b) → Map k a → Map k b Source #

Map a function over all values in the map.

mapMaybe ∷ (a → Maybe b) → Map k a → Map k b Source #

Map keys/values and collect the Just results.

mapMaybeWithKey ∷ (k → a → Maybe b) → Map k a → Map k b Source #

Map keys/values and collect the Just results.

all ∷ (a → Bool) → Map k a → Bool Source #

Determines whether all elements in the map satisfy the predicate.

mapThese ∷ (v → These a b) → Map k v → (Map k a, Map k b) Source #

A version of mapEither that works with These.