Ludwig.Dictionary

Module Members

delete

(Function)

Create a new Dictionary without the given key. If the key is not present in the Dictionary, the original Dictionary will be returned.

Example:

my-dict: {"foo": 1, "bar": 2}
my-new-dict: Dictionary.delete("foo", my-dictionary)  # => {"bar", 2}

Type Signature

 fun (String, Dictionary<a>) -> Dictionary<a>
Argument: key
Type: String
Argument: dict
Type: Dictionary<a>
Returns:
Type: Dictionary<a>

filter

(Function)

Returns a new Ludwig.Dictionary by keeping only the key, value pairs that satisfy the given predicate.

Type Signature

 fun (fun (String, a) -> Bool, Dictionary<a>) -> Dictionary<a>
Argument: f
Type: fun ( String, a) -> Bool
Argument: dict
Type: Dictionary<a>
Returns:
Type: Dictionary<a>

fromList

(Function)

Create a dictionary from a list of key, value pairs.

Example:

my-list: Dictionary.fromList([("foo", 1), ("bar", 2)])  # => {"foo": 1, "bar": 2}

Type Signature

 fun (List<(String, a)>) -> Dictionary<a>
Argument: list
Type: List<(String, a)>
Returns:
Type: Dictionary<a>

insert

(Function)

Insert a key, value pair into a Dictionary.

Return a new Dictionary constructed from the original Dictionary with the new item inserted. Any existing values associated with the key are replaced.

Example:

my-dict: Dictionary.insert("hello", "world", empty)   # => {"hello": "world"}

Type Signature

 fun (String, a, Dictionary<a>) -> Dictionary<a>
Argument: key

The key to insert.

Type: String

Argument: value

The value to insert.

Type: a

Argument: dict

The Dictionary to insert key and value to.

Type: Dictionary<a>

Returns:

A new Dictionary constructed from dict with key and value inserted.

Type: Dictionary<a>

isEmpty

(Function)

Test if a Dictionary is empty.

Example:

this-is-empty: Dictionary.isEmpty(Dictionary.empty)   # => True
this-is-not-empty: Dictionary.isEmpty({"foo": "bar"}) # => False

Type Signature

 fun (Dictionary<a>) -> Bool
Argument: dict
Type: Dictionary<a>
Returns:
Type: Bool

keys

(Function)

Get the List of keys in a Dictionary.

Example:

my-dictionary: {"foo": 1, "bar": 2}
my-keys: Dictionary.keys(my-dictionary)           # => ["foo", "bar"]

Type Signature

 fun (Dictionary<a>) -> List<String>
Argument: dict

The Dictionary to return the keys from.

Type: Dictionary<a>

Returns:

A List<String> of the keys in the dict in no particular order.

Type: List<String>

lookup

(Function)

Lookup a key in the Dictionary and return it wrapped in Ludwig.Optional if it exists. Returns None if the Ludwig.Dictionary does not contain the specified key.

Example:

my-dictionary: {"foo": "bar", "baz": "quux"}
my-foo: Dictionary.lookup("foo", my-dictionary)         # => Optional("bar")
my-bar: Dictionary.lookup("bar", my-dictionary)         # => None

Type Signature

 fun (String, Dictionary<a>) -> Optional<a>
Argument: key

The key to lookup.

Type: String

Argument: dict

The Dictionary to lookup key in.

Type: Dictionary<a>

Returns:

The value corresponding to key wrapped in Optional<a> if it exists. Returns None if dict does not contain key.

Type: Optional<a>

map

(Function)

Map over the elements in a dictionary.

Type Signature

 fun (fun (String, a) -> b, Dictionary<a>) -> Dictionary<b>
Argument: f
Type: fun ( String, a) -> b
Argument: dict
Type: Dictionary<a>
Returns:
Type: Dictionary<b>

member

(Function)

Test if a Dictionary contains a given key.

Example:

my-dictionary: {"foo": "bar", "baz": "quux"}
has-foo: Dictionary.member("foo", my-dictionary)         # => True
has-bar: Dictionary.member("bar", my-dictionary)         # => False

Type Signature

 fun (String, Dictionary<a>) -> Bool
Argument: key

The key to look for.

Type: String

Argument: dict

The dictionary to search.

Type: Dictionary<a>

Returns:

True if the dict contains key.

Type: Bool

merge

(Function)

Merge two dictionaries, creating a new dictionary that holds the union of the key-value pairs.

Example:

dict01: Dictionary.merge({"foo": 1}, {"bar": 2})   # => {"foo": 1, "bar": 2}

If there are collisions between keys, the corresponding values in the left dictionary win, and the corresponding values in the right argument are thrown away.

Example:

dict02: Dictionary.merge({"foo": 1}, {"foo": 2})   # => {"foo": 1}

Type Signature

 fun (Dictionary<a>, Dictionary<a>) -> Dictionary<a>
Argument: left
Type: Dictionary<a>
Argument: right
Type: Dictionary<a>
Returns:
Type: Dictionary<a>

null

(Function)

DEPRECATED: Use isEmpty instead.

Test if a Dictionary is empty.

Example:

this-is-empty: Dictionary.null(Dictionary.empty)   # => True
this-is-not-empty: Dictionary.null({"foo": "bar"}) # => False

Type Signature

 fun (Dictionary<a>) -> Bool
Argument: dict
Type: Dictionary<a>
Returns:
Type: Bool

reduce

(Function)

Reduce a Ludwig.Dictionary by applying the operation. The dictionary will be reduced in no particular order.

Type Signature

 fun (fun (b, String, a) -> b, b, Dictionary<a>) -> b
Argument: f
Type: fun ( b, String, a) -> b
Argument: z
Type: b
Argument: dict
Type: Dictionary<a>
Returns:
Type: b

size

(Function)

Get the number of key-value pairs in a Dictionary.

Example:

num-elems: Dictionary.size({"foo": 1, "bar": 2})  # => 2

Type Signature

 fun (Dictionary<a>) -> Int
Argument: dict
Type: Dictionary<a>
Returns:
Type: Int

toList

(Function)

Convert a dictionary to a list. The returned list has no particular order.

Example:

my-list: Dictionary.toList({"foo": 1, "bar", 2})  # => [("foo", 1), ("bar", 2)]

Type Signature

 fun (Dictionary<a>) -> List<(String, a)>
Argument: dict
Type: Dictionary<a>
Returns:
Type: List<(String, a)>

values

(Function)

Return a List<a> of the values in the Ludwig.Dictionary in no particular order.

Example:

my-dictionary: {"foo": "bar", "baz": "quux"}
my-values: Dictionary.values(my-dictionary)              # => ["bar", "quux"]

Type Signature

 fun (Dictionary<a>) -> List<a>
Argument: dict

The Dictionary to return the keys from.

Type: Dictionary<a>

Returns:

A List of the values in the dict in no particular order.

Type: List<a>

empty

(Value)

empty:
  __Ludwig_Dictionary_empty

The empty Dictionary.

Example:

my-dict: empty   # => {}