Extension methods for Loyc collection interfaces
This class contains extension methods that are provided as part of various Loyc.Collections interfaces. For example, it provides methods such as IndexOf(), Contains() and CopyTo(), that the traditional ICollection<T> and IList<T> interfaces require the author to write himself.
For covariant collections such as IReadOnlyCollection<T> and IListSource<T>, the CLR actually prohibits methods such as Contains(T) and IndexOf(T), because T is not allowed in "input" positions. Therefore, these extension methods must be used to fill the gap. Even methods such as bool TryGet(int, out T) are prohibited, so TryGet() has the signature T TryGet(ref bool failed) instead, and extension methods provide the original version of the method in addition.
|
static void | Resize< T > (this IListRangeMethods< T > list, int newSize) |
|
static void | Resize< T > (this IListEx< T > list, int newSize) |
|
static bool | Any (this ICount c) |
| Returns true if the collection contains any elements. More...
|
|
static bool | GetAndEdit< K, V > (IDictionary< K, V > dict, K key, ref V value, DictEditMode mode) |
| Default implementation of IDictionaryEx<K, V>.GetAndEdit. More...
|
|
static bool | AddIfNotPresent< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Adds a key/value pair to the dictionary if the key is not present. If the key is already present, this method has no effect. More...
|
|
static bool | TryAdd< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
|
static V | GetOrAdd< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Adds a key/value pair to the dictionary if the key is not already present, and returns the existing or new value. More...
|
|
static Maybe< V > | AddOrGetExisting< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Adds a new key/value pair if the key was not present, or gets the existing value if the key was present. More...
|
|
static bool | ReplaceIfPresent< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Replaces an item in the map if the key was already present. If the key was not already present, this method has no effect. More...
|
|
static Maybe< V > | SwapIfPresent< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Replaces an item in the map if the key was already present. If the key was not already present, this method has no effect. More...
|
|
static Maybe< V > | SetAndGet< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
|
static Maybe< V > | GetAndSet< K, V > (this IDictionaryEx< K, V > dict, K key, V value) |
| Associates a key with a value in the dictionary, and gets the old value if the key was already present. More...
|
|
static bool | TryGet< T > (this IListSource< T > list, int index, ref T value) |
| Tries to get a value from the list at the specified index. More...
|
|
static T | TryGet< T > (this IListSource< T > list, int index, T defaultValue) |
| Tries to get a value from the list at the specified index. More...
|
|
static Maybe< T > | TryGet< T > (this IListSource< T > list, int index) |
|
static bool | HasIndex< T > (this IListSource< T > list, int index) |
| Uses list.TryGet(index) to find out if the specified index is valid. More...
|
|
static ? int | FirstIndexOf< T > (this IReadOnlyList< T > list, T item) |
| Determines the index of a specific value. More...
|
|
static int | IndexOf< T > (this IReadOnlyList< T > list, T item) |
| Determines the index of a specific value. More...
|
|
static void | CopyTo< T > (this IReadOnlyList< T > c, T[] array, int arrayIndex) |
|
static ? int | FirstIndexWhere< T > (this IReadOnlyList< T > source, Func< T, bool > pred) |
| Gets the lowest index at which a condition is true, or null if nowhere. More...
|
|
static int | IndexWhere< T > (this IReadOnlyList< T > source, Func< T, bool > pred) |
| Gets the lowest index at which a condition is true, or -1 if nowhere. More...
|
|
static ? int | FinalIndexWhere< T > (this IReadOnlyList< T > source, Func< T, bool > pred) |
| Gets the highest index at which a condition is true, or null if nowhere. More...
|
|
static int | LastIndexWhere< T > (this IReadOnlyList< T > source, Func< T, bool > pred) |
| Gets the highest index at which a condition is true, or -1 if nowhere. More...
|
|
static bool | TryGet< T > (this INegListSource< T > list, int index, ref T value) |
| Tries to get a value from the list at the specified index. More...
|
|
static ? int | IndexOf< T > (this INegListSource< T > list, T item) |
| Determines the index of a specific value. More...
|
|
static ? int | NextHigherIndex< T > (this ISparseListSource< T > list, int? index) |
| Gets the next higher index that is not classified as an empty space, or null if there are no non-blank higher indexes. More...
|
|
static ? int | NextLowerIndex< T > (this ISparseListSource< T > list, int? index) |
| Gets the next lower index that is not classified as an empty space, or null if there are no non-blank lower indexes. More...
|
|
static IEnumerable< KeyValuePair< int, T > > | Items< T > (this ISparseListSource< T > list) |
| Returns the non-cleared items in the sparse list, along with their indexes, sorted by index. More...
|
|
static bool | TryPop< T > (this IPop< T > c, out T value) |
|
static bool | TryPeek< T > (this IPop< T > c, out T value) |
|
static T | PopFirst< T > (this IDeque< T > c) |
|
static T | PopLast< T > (this IDeque< T > c) |
|
static T | PeekFirst< T > (this IDeque< T > c) |
|
static T | PeekLast< T > (this IDeque< T > c) |
|