plutus-tx-1.36.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

lift :: Map 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

lift :: Quote m => Map k v -> m Exp Source #

liftTyped :: forall (m :: Type -> Type). 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

traverse :: Applicative 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 :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Map k v -> c (Map k v) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall 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 => (forall d. Data d => c (t d)) -> Maybe (c (Map k v)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v)) Source #

gmapT :: (forall b. Data b => b -> b) -> Map k v -> Map k v Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Map k v -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Map k v -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Map k v -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Map k v -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Map k v -> m (Map k v) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k v -> m (Map k v) Source #

gmapMo :: MonadPlus m => (forall 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) :: Type -> Type Source #

Methods

from :: Map k v -> Rep (Map k v) x Source #

to :: Rep (Map k v) x -> Map k v Source #

(Show k, Show v) => Show (Map k v) Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

showsPrec :: Int -> Map k v -> ShowS Source #

show :: Map 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

rnf :: Map 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

compare :: Map 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 #

max :: Map k v -> Map k v -> Map k v Source #

min :: Map 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

(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

mempty :: Map 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

pretty :: Map k v -> Doc ann

prettyList :: [Map k v] -> Doc ann

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

Defined in PlutusTx.AssocMap

Methods

schema :: Schema referencedTypes Source #

Typeable DefaultUni Map Source # 
Instance details

Defined in PlutusTx.AssocMap

Methods

typeRep :: Proxy Map -> RTCompile DefaultUni fun (Type TyName DefaultUni ()) Source #

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.36.0.0-8y1X6QaF1WM5mIhDTsyzym" '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.

empty :: Map k v Source #

An empty Map.

null :: Map 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.

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.

toList :: Map k v -> [(k, v)] Source #

keys :: Map 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.

elems :: Map k v -> [v] Source #

Return all elements of the map.

lookup :: forall 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 :: forall k v. Eq k => k -> Map k v -> Bool Source #

Is the key a member of the map?

insert :: forall 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 :: forall 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 :: forall 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 :: forall 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.