Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Map k a
- lookup :: forall k a. (ToData k, UnsafeFromData a) => k -> Map k a -> Maybe a
- member :: forall k a. ToData k => k -> Map k a -> Bool
- insert :: forall k a. (ToData k, ToData a) => k -> a -> Map k a -> Map k a
- delete :: forall k a. ToData k => k -> Map k a -> Map k a
- singleton :: forall k a. (ToData k, ToData a) => k -> a -> Map k a
- empty :: forall k a. Map k a
- null :: forall 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 :: forall k a. (ToData k, ToData a) => [(k, a)] -> Map k a
- unsafeFromList :: (ToData k, ToData a) => [(k, a)] -> Map k a
- unsafeFromBuiltinList :: forall k a. BuiltinList (BuiltinPair BuiltinData BuiltinData) -> Map k a
- noDuplicateKeys :: forall k a. Map k a -> Bool
- all :: forall k a. UnsafeFromData a => (a -> Bool) -> Map k a -> Bool
- any :: forall k a. UnsafeFromData a => (a -> Bool) -> Map k a -> Bool
- union :: forall k a b. (UnsafeFromData a, UnsafeFromData b, ToData a, ToData b) => Map k a -> Map k b -> Map k (These a b)
- unionWith :: forall k a. (UnsafeFromData a, ToData a) => (a -> a -> a) -> Map k a -> Map k a -> Map k a
- keys :: forall k a. Map k a -> BuiltinList BuiltinData
- map :: forall k a b. (UnsafeFromData a, ToData b) => (a -> b) -> Map k a -> Map k b
- mapThese :: forall v k a b. (ToData a, ToData b, UnsafeFromData v) => (v -> These a b) -> Map k v -> (Map k a, Map k b)
- foldr :: forall 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 # | |
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 # | |
Defined in PlutusTx.Data.AssocMap prettyList :: [Map k a] -> Doc ann | |
Typeable DefaultUni Map Source # | |
lookup :: forall 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 :: forall 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 :: forall 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 :: forall 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 :: forall 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 :: forall k a. Map k a -> Bool Source #
Check if the Map
is well-defined. Warning: this operation is O(n^2).
any :: forall k a. UnsafeFromData a => (a -> Bool) -> Map k a -> Bool Source #
Check if any value in the Map
satisfies the predicate.
union :: forall 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 :: forall 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 :: forall k a. Map k a -> BuiltinList BuiltinData Source #
mapThese :: forall 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 :: forall a b k. UnsafeFromData a => (a -> b -> b) -> b -> Map k a -> b Source #