- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Get started with Canton Network App Dev Quickstart
- Using the JSON Ledger API
- Get started with smart contract development
- Basic contracts
- Test templates using Daml scripts
- Build the Daml Archive (.dar) file
- Data types
- Transform contracts using choices
- Add constraints to a contract
- Parties and authority
- Compose choices
- Handle exceptions
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Application development
- Getting started
- Development how-tos
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- Overview: Template Structure
- Reference: Templates
- Reference: Choices
- Reference: Updates
- Reference: Data Types
- Reference: Built-in Functions
- Reference: Expressions
- Reference: Functions
- Reference: Daml File Structure
- Reference: Daml Packages
- Reference: Contract Keys
- Reference: Interfaces
- Reference: Exceptions (Deprecated)
- Daml standard library
- DA.Action.State.Class
- DA.Action.State
- DA.Action
- DA.Assert
- DA.Bifunctor
- DA.Crypto.Text
- DA.Date
- DA.Either
- DA.Exception
- DA.Fail
- DA.Foldable
- DA.Functor
- DA.Internal.Interface.AnyView.Types
- DA.Internal.Interface.AnyView
- DA.List.BuiltinOrder
- DA.List.Total
- DA.List
- DA.Logic
- DA.Map
- DA.Math
- DA.Monoid
- DA.NonEmpty.Types
- DA.NonEmpty
- DA.Numeric
- DA.Optional
- DA.Record
- DA.Semigroup
- DA.Set
- DA.Stack
- DA.Text
- DA.TextMap
- DA.Time
- DA.Traversable
- DA.Tuple
- DA.Validation
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Daml Script
- Smart contract upgrading reference
- Glossary of concepts
DA.TextMap¶
TextMap - A map is an associative array data type composed of a collection of key/value pairs such that, each possible key appears at most once in the collection.
Functions¶
- fromListWithL
: (a -> a -> a) -> [(Text, a)] -> TextMap a
Create a map from a list of key/value pairs with a combining function. The combining function is only used when a key appears multiple times in the list and it takes two arguments: the first one is the new value being inserted at that key and the second one is the value accumulated so far at that key. Examples:
>>> fromListWithL (++) [("A", [1]), ("A", [2]), ("B", [2]), ("B", [1]), ("A", [3])] fromList [("A", [3, 2, 1]), ("B", [1, 2])] >>> fromListWithL (++) [] == (empty : TextMap [Int]) True
- fromListWithR
: (a -> a -> a) -> [(Text, a)] -> TextMap a
Create a map from a list of key/value pairs like
fromListWithLwith the combining function flipped. Examples:>>> fromListWithR (++) [("A", [1]), ("A", [2]), ("B", [2]), ("B", [1]), ("A", [3])] fromList [("A", [1, 2, 3]), ("B", [2, 1])] >>> fromListWithR (++) [] == (empty : TextMap [Int]) True
- fromListWith
: (a -> a -> a) -> [(Text, a)] -> TextMap a
Warning
DEPRECATED:
Daml compatibility helper, use ‘fromListWithR’ instead of ‘fromListWith’
- toList
-
Convert the map to a list of key/value pairs where the keys are in ascending order.
- filter
: (v -> Bool) -> TextMap v -> TextMap v
Filter the
TextMapusing a predicate: keep only the entries where the value satisfies the predicate.
- filterWithKey
: (Text -> v -> Bool) -> TextMap v -> TextMap v
Filter the
TextMapusing a predicate: keep only the entries which satisfy the predicate.
- delete
: Text -> TextMap a -> TextMap a
Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.
- insert
: Text -> a -> TextMap a -> TextMap a
Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value.
- insertWith
: (v -> v -> v) -> Text -> v -> TextMap v -> TextMap v
Insert a new key/value pair in the map. If the key is already present in the map, it is combined with the previous value using the given function
f new_value old_value.
- union
: TextMap a -> TextMap a -> TextMap a
The union of two maps, preferring the first map when equal keys are encountered.
- merge
: (Text -> a -> Optional c) -> (Text -> b -> Optional c) -> (Text -> a -> b -> Optional c) -> TextMap a -> TextMap b -> TextMap c
Merge two maps.
merge f g h x yappliesfto all key/value pairs whose key only appears inx,gto all pairs whose key only appears inyandhto all pairs whose key appears in bothxandy. In the end, all pairs yieldingSomeare collected as the result.