Class Map
Static Extension class for Map interface implementers.
Inheritance
Namespace: Towel.DataStructures
Assembly: Towel.dll
Syntax
public static class Map : object
Methods
| Improve this Doc View SourceAdd<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. |
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> | (
|
Type Parameters
Name | Description |
---|---|
T | The type of values in the map. |
TKey | The type of keys in the map. |
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> |
|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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> | (
|
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
TKey | The type of the key. |
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> |
|
Type Parameters
Name | Description |
---|---|
T | The type of values in the map. |
TKey | The type of keys in the map. |
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> |
|
Type Parameters
Name | Description |
---|---|
T | The type of values in the map. |
TKey | The type of keys in the map. |
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> | (
|
Type Parameters
Name | Description |
---|---|
T | The type of values in the map. |
TKey | The type of keys in the map. |
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> | (
|
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. |