Table of Contents

Class Map<TK, TV>

Namespace
Map
Assembly
Map.dll
public sealed class Map<TK, TV> : IReadOnlyDictionary<TK, TV>, IReadOnlyCollection<KeyValuePair<TK, TV>>, IEnumerable<KeyValuePair<TK, TV>>, IEnumerable where TK : notnull

Type Parameters

TK
TV
Inheritance
Map<TK, TV>
Implements
Inherited Members

Constructors

Map()

public Map()

Map(IEqualityComparer<TK>)

public Map(IEqualityComparer<TK> comparer)

Parameters

comparer IEqualityComparer<TK>

Fields

Empty

public static readonly Map<TK, TV> Empty

Field Value

Map<TK, TV>

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

IsEmpty

public bool IsEmpty { get; }

Property Value

bool

this[TK]

Gets the element that has the specified key in the read-only dictionary.

public TV this[TK key] { get; }

Parameters

key TK

The key to locate.

Property Value

TV

The element that has the specified key in the read-only dictionary.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key is not found.

Keys

public MapKeyCollection<TK, TV> Keys { get; }

Property Value

MapKeyCollection<TK, TV>

Values

public MapValueCollection<TK, TV> Values { get; }

Property Value

MapValueCollection<TK, TV>

Methods

Add(TK, TV)

public Map<TK, TV> Add(TK key, TV value)

Parameters

key TK
value TV

Returns

Map<TK, TV>

ContainsKey(TK)

Determines whether the read-only dictionary contains an element that has the specified key.

public bool ContainsKey(TK key)

Parameters

key TK

The key to locate.

Returns

bool

true if the read-only dictionary contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

Equals(Map<TK, TV>?)

public bool Equals(Map<TK, TV>? other)

Parameters

other Map<TK, TV>

Returns

bool

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Exists(Func<TK, TV, bool>)

Determines whether the map contains elements that satisfy the specified predicate.

public bool Exists(Func<TK, TV, bool> pred)

Parameters

pred Func<TK, TV, bool>

A function to test each element for a condition.

Returns

bool

true if the map contains an element that satisfies the condition; otherwise, false.

Filter(Func<TV, TV, bool>)

Filters the map, retaining only elements that satisfy the specified predicate.

public Map<TK, TV> Filter(Func<TV, TV, bool> action)

Parameters

action Func<TV, TV, bool>

A function to test each value for a condition.

Returns

Map<TK, TV>

A new Map<TK, TV> containing the elements that satisfy the condition.

FindKey(Func<TK, bool>)

Finds the first key in the map that satisfies the specified predicate.

public TK FindKey(Func<TK, bool> pred)

Parameters

pred Func<TK, bool>

A function to test each key for a condition.

Returns

TK

The key that satisfies the condition.

Exceptions

KeyNotFoundException

Thrown if no key satisfies the condition.

FoldKeys<TState>(TState, Func<TState, TK, TState>)

Aggregates the keys of the map using the specified function.

public TState FoldKeys<TState>(TState seed, Func<TState, TK, TState> action)

Parameters

seed TState

The initial accumulator value.

action Func<TState, TK, TState>

A function to aggregate the state and each key.

Returns

TState

The final accumulated state.

Type Parameters

TState

The type of the accumulator state.

FoldValues<TState>(TState, Func<TState, TV, TState>)

Aggregates the values of the map using the specified function.

public TState FoldValues<TState>(TState seed, Func<TState, TV, TState> action)

Parameters

seed TState

The initial accumulator value.

action Func<TState, TV, TState>

A function to aggregate the state and each value.

Returns

TState

The final accumulated state.

Type Parameters

TState

The type of the accumulator state.

ForEach(Action<TK, TV>)

Executes the specified action on each element of the map.

public void ForEach(Action<TK, TV> action)

Parameters

action Action<TK, TV>

The action to execute on each key-value pair.

Get(TK)

public TV Get(TK key)

Parameters

key TK

Returns

TV

GetEnumerator()

public MapEnumerator<TK, TV> GetEnumerator()

Returns

MapEnumerator<TK, TV>

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Iter(Func<TK, TV, bool>)

Executes a delegate on the elements of the map

public bool Iter(Func<TK, TV, bool> action)

Parameters

action Func<TK, TV, bool>

Returns

bool

True if the iteration completed all elements, or False if aborted early.

MapCar<NK, NV>(Func<TK, TV, (NK, NV)>, IEqualityComparer<NK>?)

Transforms the elements of the map using the specified function.

public Map<NK, NV> MapCar<NK, NV>(Func<TK, TV, (NK, NV)> action, IEqualityComparer<NK>? comparer = null)

Parameters

action Func<TK, TV, (NK, NV)>

A function to transform each key-value pair.

comparer IEqualityComparer<NK>

An optional equality comparer for the new keys.

Returns

Map<NK, NV>

A new Map<TK, TV> containing the transformed elements.

Type Parameters

NK

The type of the new keys.

NV

The type of the new values.

Merge(Map<TK, TV>)

Merges another map into this one. Defaults to 'Prefer Right' where values in 'other' overwrite this map.

public Map<TK, TV> Merge(Map<TK, TV> other)

Parameters

other Map<TK, TV>

Returns

Map<TK, TV>

Merge(Map<TK, TV>, Func<TK, TV, TV, TV>?)

Merges another map into this one using a conflict resolution strategy.

public Map<TK, TV> Merge(Map<TK, TV> other, Func<TK, TV, TV, TV>? conflictResolver)

Parameters

other Map<TK, TV>

The other map to merge.

conflictResolver Func<TK, TV, TV, TV>

An optional thunk called when keys conflict: (key, leftValue, rightValue) => resolvedValue. Pass null to default to picking the right value (other overwrites this).

Returns

Map<TK, TV>

Mutate(Action<TransientMap<TK, TV>>)

Creates a transient version of the map, applies the specified mutation action, and returns an immutable map.

public Map<TK, TV> Mutate(Action<TransientMap<TK, TV>> action)

Parameters

action Action<TransientMap<TK, TV>>

The action to apply to the transient map.

Returns

Map<TK, TV>

A new Map<TK, TV> with the mutations applied.

Remove(TK)

public Map<TK, TV> Remove(TK key)

Parameters

key TK

Returns

Map<TK, TV>

ToTransient()

public TransientMap<TK, TV> ToTransient()

Returns

TransientMap<TK, TV>

TryGetValue(TK, out TV)

Gets the value that is associated with the specified key.

public bool TryGetValue(TK key, out TV value)

Parameters

key TK

The key to locate.

value TV

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.