Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Static Public Member Functions | List of all members
Loyc.Collections.LCInterfaces Class Reference

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. More...


Source files:

Remarks

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.

Extension methods for Loyc collection interfaces

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 Public Member Functions

static bool Any (this ICount c)
 Returns true if the collection contains any elements. 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)
 Tries to get a value from the list at the specified index. More...
 
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 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 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 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 T[] ToArray< T > (this IReadOnlyList< T > c)
 Copies the contents of an IListSource to an array. More...
 
static T LastOrDefault< T > (this IReadOnlyList< T > list)
 
static T FirstOrDefault< T > (this IReadOnlyList< T > list)
 
static T FirstOrDefault< T > (this IListSource< T > list)
 
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 T TryGet< T > (this INegListSource< T > list, int index, T defaultValue)
 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 T Pop< T > (this IPop< T > c)
 
static T Peek< T > (this IPop< T > c)
 
static bool TryPop< T > (this IPop< T > c, out T value)
 
static bool TryPeek< T > (this IPop< T > c, out T value)
 
static T TryPop< T > (this IPop< T > c)
 
static T TryPeek< T > (this IPop< T > c)
 
static T TryPop< T > (this IPop< T > c, T defaultValue)
 
static T TryPeek< T > (this IPop< T > c, T defaultValue)
 
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)
 
static void Resize< T > (this IListRangeMethods< T > list, int newSize)
 

Member Function Documentation

static bool Loyc.Collections.LCInterfaces.Any ( this ICount  c)
inlinestatic

Returns true if the collection contains any elements.

static bool Loyc.Collections.LCInterfaces.HasIndex< T > ( this IListSource< T >  list,
int  index 
)
inlinestatic

Uses list.TryGet(index) to find out if the specified index is valid.

Returns
true if the specified index is valid, false if not.
static int Loyc.Collections.LCInterfaces.IndexOf< T > ( this INegListSource< T >  list,
item 
)
inlinestatic

Determines the index of a specific value.

Returns
The index of the value, if found, or -1 if it was not found.

At first, this method was a member of IListSource itself, just in case the source might have some kind of fast lookup logic (e.g. binary search) or custom comparer. However, since the item to find is an "in" argument, it would prevent IListSource from being marked covariant when I upgrade to C# 4.

static int Loyc.Collections.LCInterfaces.IndexOf< T > ( this IReadOnlyList< T >  list,
item 
)
inlinestatic

Determines the index of a specific value.

Returns
The index of the value, if found, or -1 if it was not found.

At first, this method was a member of IListSource itself, just in case the source might have some kind of fast lookup logic (e.g. binary search) or custom comparer. However, since the item to find is an "in" argument, it would prevent IListSource from being marked covariant when I upgrade to C# 4.

static int Loyc.Collections.LCInterfaces.IndexWhere< T > ( this IReadOnlyList< T >  source,
Func< T, bool >  pred 
)
inlinestatic

Gets the lowest index at which a condition is true, or -1 if nowhere.

static IEnumerable<KeyValuePair<int, T> > Loyc.Collections.LCInterfaces.Items< T > ( this ISparseListSource< T >  list)
inlinestatic

Returns the non-cleared items in the sparse list, along with their indexes, sorted by index.

The returned sequence should exactly match the set of indexes for which list.IsSet(Key) returns true.

static int Loyc.Collections.LCInterfaces.LastIndexWhere< T > ( this IReadOnlyList< T >  source,
Func< T, bool >  pred 
)
inlinestatic

Gets the highest index at which a condition is true, or -1 if nowhere.

static int Loyc.Collections.LCInterfaces.NextHigherIndex< T > ( this ISparseListSource< T >  list,
int?  index 
)
inlinestatic

Gets the next higher index that is not classified as an empty space, or null if there are no non-blank higher indexes.

This extension method works by calling NextHigherItem().

static int Loyc.Collections.LCInterfaces.NextLowerIndex< T > ( this ISparseListSource< T >  list,
int?  index 
)
inlinestatic

Gets the next lower index that is not classified as an empty space, or null if there are no non-blank lower indexes.

This extension method works by calling NextHigherItem().

static T [] Loyc.Collections.LCInterfaces.ToArray< T > ( this IReadOnlyList< T >  c)
inlinestatic

Copies the contents of an IListSource to an array.

static bool Loyc.Collections.LCInterfaces.TryGet< T > ( this INegListSource< T >  list,
int  index,
ref T  value 
)
inlinestatic

Tries to get a value from the list at the specified index.

Parameters
indexThe index to access. Valid indexes are between Min and Max.
valueA variable that will be changed to the retrieved value. If the index is not valid, this variable is left unmodified.
Returns
True on success, or false if the index was not valid.
static T Loyc.Collections.LCInterfaces.TryGet< T > ( this INegListSource< T >  list,
int  index,
defaultValue 
)
inlinestatic

Tries to get a value from the list at the specified index.

Parameters
indexThe index to access. Valid indexes are between Min and Max.
defaultValueA value to return if the index is not valid.
Returns
The retrieved value, or defaultValue if the index provided was not valid.
static bool Loyc.Collections.LCInterfaces.TryGet< T > ( this IListSource< T >  list,
int  index,
ref T  value 
)
inlinestatic

Tries to get a value from the list at the specified index.

Parameters
indexThe index to access. Valid indexes are between 0 and Count-1.
valueA variable that will be changed to the retrieved value. If the index is not valid, this variable is left unmodified.
Returns
True on success, or false if the index was not valid.
static T Loyc.Collections.LCInterfaces.TryGet< T > ( this IListSource< T >  list,
int  index,
defaultValue 
)
inlinestatic

Tries to get a value from the list at the specified index.

Parameters
indexThe index to access. Valid indexes are between 0 and Count-1.
defaultValueA value to return if the index is not valid.
Returns
The retrieved value, or defaultValue if the index provided was not valid.
static Maybe<T> Loyc.Collections.LCInterfaces.TryGet< T > ( this IListSource< T >  list,
int  index 
)
inlinestatic

Tries to get a value from the list at the specified index.

Parameters
indexThe index to access. Valid indexes are between 0 and Count-1.
Returns
The retrieved value wrapped in Maybe{T}, if any.