Module DA.Set

Note: This is only supported in DAML-LF 1.11 or later.

This module exports the generic set type Set k and associated functions. This module should be imported qualified, for example:

import DA.Set (Set)
import DA.Set qualified as S

This will give access to the Set type, and the various operations as S.lookup, S.insert, S.fromList, etc.

Set k internally uses the built-in order for the type k. This means that keys that contain functions are not comparable and will result in runtime errors. To prevent this, the Ord k instance is required for most set operations. It is recommended to only use Set k for key types that have an Ord k instance that is derived automatically using deriving:

data K = ...
  deriving (Eq, Ord)

This includes all built-in types that aren’t function types, such as Int, Text, Bool, (a, b) assuming a and b have default Ord instances, Optional t and [t] assuming t has a default Ord instance, Map k v assuming k and v have default Ord instances, and Set k assuming k has a default Ord instance.

Data Types

data Set k

The type of a set. This is a wrapper over the Map type.

Set

Field Type Description
map Map k ()  

instance Ord k => Monoid (Set k)

instance Ord k => Semigroup (Set k)

instance IsParties (Set Party)

instance Ord k => Eq (Set k)

instance Ord k => Ord (Set k)

instance (Ord k, Show k) => Show (Set k)

Functions

empty

: Set k

The empty set.

size

: Set k -> Int

The number of elements in the set.

toList

: Set k -> [k]

Convert the set to a list of elements.

fromList

: Ord k => [k] -> Set k

Create a set from a list of elements.

toMap

: Set k -> Map k ()

Convert a Set into a Map.

fromMap

: Map k () -> Set k

Create a Set from a Map.

member

: Ord k => k -> Set k -> Bool

Is the element in the set?

null

: Set k -> Bool

Is this the empty set?

insert

: Ord k => k -> Set k -> Set k

Insert an element in a set. If the set already contains the element, this returns the set unchanged.

filter

: Ord k => (k -> Bool) -> Set k -> Set k

Filter all elements that satisfy the predicate.

delete

: Ord k => k -> Set k -> Set k

Delete an element from a set.

singleton

: Ord k => k -> Set k

Create a singleton set.

union

: Ord k => Set k -> Set k -> Set k

The union of two sets.

intersection

: Ord k => Set k -> Set k -> Set k

The intersection of two sets.

difference

: Ord k => Set k -> Set k -> Set k

difference x y returns the set consisting of all elements in x that are not in y.

> > > fromList [1, 2, 3] difference fromList [1, 4] > > > fromList [2, 3]