Show / Hide Table of Contents

Class Map

Static Extension class for Map interface implementers.

Inheritance
System.Object
Map
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public static class Map : object

Methods

| Improve this Doc View Source

Add<T, TKey>(IMap<T, TKey>, TKey, T)

Adds a value to a map by key.

Declaration
public static void Add<T, TKey>(this IMap<T, TKey> map, TKey key, T value)
Parameters
Type Name Description
IMap<T, TKey> map

The map to add the value to.

TKey key

The key of the value to get.

T value

The value to add to the map.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

AddOrUpdate<T, TKey>(IMap<T, TKey>, TKey, T, Func<T, T>)

Adds or updates the value at the given key.

Declaration
public static (bool Existed, T OldValue) AddOrUpdate<T, TKey>(this IMap<T, TKey> map, TKey key, T value, Func<T, T> update)
Parameters
Type Name Description
IMap<T, TKey> map

The map to add or update the value in.

TKey key

The key of the value to add or update.

T value

The value to add if not already present.

Func<T, T> update

The function to update the value if present.

Returns
Type Description
System.ValueTuple<System.Boolean, T>

( Existed, T OldValue)

  • Existed: true if the key was already in the map
  • T OldValue: the value relative tothe key before to the update if it existed or default
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

AddOrUpdate<T, TKey, TUpdate>(IMap<T, TKey>, TKey, T, TUpdate)

Adds or updates the value at the given key.

Declaration
public static (bool Existed, T OldValue) AddOrUpdate<T, TKey, TUpdate>(this IMap<T, TKey> map, TKey key, T value, TUpdate update = default(TUpdate))
    where TUpdate : struct, IFunc<T, T>
Parameters
Type Name Description
IMap<T, TKey> map

The map to add or update the value in.

TKey key

The key of the value to add or update.

T value

The value to add if not already present.

TUpdate update

The function to update the value if present.

Returns
Type Description
System.ValueTuple<System.Boolean, T>
  • Existed: true if the key was already in the map
  • T OldValue: the value relative tothe key before to the update if it existed or default
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

TUpdate

The type of function to update the value.

| Improve this Doc View Source

Get<T, TKey>(IMap<T, TKey>, TKey)

Gets a value in a map relative to a key.

Declaration
public static T Get<T, TKey>(this IMap<T, TKey> map, TKey key)
Parameters
Type Name Description
IMap<T, TKey> map

The map to set the value in.

TKey key

The key.

Returns
Type Description
T

The value relative to the key.

Type Parameters
Name Description
T

The type of the value.

TKey

The type of the key.

| Improve this Doc View Source

Keys<T, TKey>(IMap<T, TKey>, Action<TKey>)

Performs a function on every key in a map.

Declaration
public static void Keys<T, TKey>(this IMap<T, TKey> map, Action<TKey> step)
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the keys of.

Action<TKey> step

The step function to perform on every key.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Keys<T, TKey, TStep>(IMap<T, TKey>, TStep)

Performs a function on every key in a map.

Declaration
public static void Keys<T, TKey, TStep>(this IMap<T, TKey> map, TStep step = default(TStep))
    where TStep : struct, IAction<TKey>
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the keys of.

TStep step

The step function to perform on every key.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

TStep

The type of step function to perform on every key.

| Improve this Doc View Source

KeysBreak<T, TKey>(IMap<T, TKey>, Func<TKey, StepStatus>)

Performs a function on every key in a map.

Declaration
public static StepStatus KeysBreak<T, TKey>(this IMap<T, TKey> map, Func<TKey, StepStatus> step)
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the keys of.

Func<TKey, StepStatus> step

The step function to perform on every key.

Returns
Type Description
StepStatus

The status of the traversal.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Pairs<T, TKey>(IMap<T, TKey>, Action<(T Value, TKey Key)>)

Performs a function on every pair in a map.

Declaration
public static void Pairs<T, TKey>(this IMap<T, TKey> map, Action<(T Value, TKey Key)> step)
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the pairs of.

Action<System.ValueTuple<T, TKey>> step

The step function to perform on every pair.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Pairs<T, TKey, TStep>(IMap<T, TKey>, TStep)

Performs a function on every pair in a map.

Declaration
public static void Pairs<T, TKey, TStep>(this IMap<T, TKey> map, TStep step = default(TStep))
    where TStep : struct, IAction<(T Value, TKey Key)>
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the pairs of.

TStep step

The step function to perform on every pair.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

TStep

The type of step function to perform on every pair.

| Improve this Doc View Source

PairsBreak<T, TKey>(IMap<T, TKey>, Func<(T Value, TKey Key), StepStatus>)

Performs a function on every pair in a map.

Declaration
public static StepStatus PairsBreak<T, TKey>(this IMap<T, TKey> map, Func<(T Value, TKey Key), StepStatus> step)
Parameters
Type Name Description
IMap<T, TKey> map

The map to traverse the pairs of.

Func<System.ValueTuple<T, TKey>, StepStatus> step

The step function to perform on every pair.

Returns
Type Description
StepStatus

The status of the traversal.

Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Set<T, TKey>(IMap<T, TKey>, TKey, T)

Sets a value in a map relative to a key.

Declaration
public static (bool Existed, T OldValue) Set<T, TKey>(this IMap<T, TKey> map, TKey key, T value)
Parameters
Type Name Description
IMap<T, TKey> map

The map to set the value in.

TKey key

The key.

T value

The value.

Returns
Type Description
System.ValueTuple<System.Boolean, T>

( Existed, T OldValue)

  • Existed: true if the key was already in the map
  • T OldValue: the value relative tothe key before to the update if it existed or default
Type Parameters
Name Description
T

The type of the value.

TKey

The type of the key.

| Improve this Doc View Source

TryAddOrUpdate<T, TKey>(IMap<T, TKey>, TKey, T, Func<T, T>)

Tries to add or update the value at the given key.

Declaration
public static (bool Success, Exception? Exception, bool? Existed, T OldValue) TryAddOrUpdate<T, TKey>(this IMap<T, TKey> map, TKey key, T value, Func<T, T> update)
Parameters
Type Name Description
IMap<T, TKey> map

The map to add or update the value in.

TKey key

The key of the value to add or update.

T value

The value to add if not already present.

Func<T, T> update

The function to update the value if present.

Returns
Type Description
System.ValueTuple<System.Boolean, System.Nullable<Exception>, System.Nullable<System.Boolean>, T>
  • Success: true if the value was added or updated or false if not.
  • ? Exception: the exception that occured if the add or update failed
  • ? Existed: true if the key-value pair was added or updated or false
  • T? OldValue: the previous value if the key existed before the add or update operation
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

TryUpdate<T, TKey>(IMap<T, TKey>, TKey, Func<T, T>)

Tries to update a value in the map the relative key exists.

Declaration
public static (bool Success, Exception? Exception, T OldValue, T NewValue) TryUpdate<T, TKey>(this IMap<T, TKey> map, TKey key, Func<T, T> update)
Parameters
Type Name Description
IMap<T, TKey> map

The map to update the value in.

TKey key

The key of the value to update.

Func<T, T> update

The function to update the value relative to the key.

Returns
Type Description
System.ValueTuple<System.Boolean, System.Nullable<Exception>, T, T>
  • Success: true if the key was found or false if not
  • ? Exception: the exception that occured if the update failed
  • T? OldValue: the value if the key was found or default if not
  • T? NewValue: the value if the key was found or default if not
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Update<T, TKey>(IMap<T, TKey>, TKey, Func<T, T>)

Updates a value in the map the relative key exists.

Declaration
public static (T OldValue, T NewValue) Update<T, TKey>(this IMap<T, TKey> map, TKey key, Func<T, T> update)
Parameters
Type Name Description
IMap<T, TKey> map

The map to update the value in.

TKey key

The key of the value to update.

Func<T, T> update

The function to update the value relative to the key.

Returns
Type Description
System.ValueTuple<T, T>

(T OldValue, T NewValue)

  • T OldValue: the value relative tothe key before to the update
  • T NewValue: the value relative tothe key after to the update
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

| Improve this Doc View Source

Update<T, TKey, TUpdate>(IMap<T, TKey>, TKey, TUpdate)

Updates a value in the map the relative key exists.

Declaration
public static (T OldValue, T NewValue) Update<T, TKey, TUpdate>(this IMap<T, TKey> map, TKey key, TUpdate update = default(TUpdate))
    where TUpdate : struct, IFunc<T, T>
Parameters
Type Name Description
IMap<T, TKey> map

The map to update the value in.

TKey key

The key of the value to update.

TUpdate update

The function to update the value relative to the key.

Returns
Type Description
System.ValueTuple<T, T>

(T OldValue, T NewValue)

  • T OldValue: the value relative tothe key before to the update
  • T NewValue: the value relative tothe key after to the update
Type Parameters
Name Description
T

The type of values in the map.

TKey

The type of keys in the map.

TUpdate

The type of function to update the value.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX