Enhanced C#
Language of your choice: library documentation
Static Public Member Functions | List of all members
Loyc.Collections.LinqToLists Class Reference

This class enhances LINQ-to-Objects with extension methods that preserve the interface (e.g. Take(IList<int>) returns a struct that implements IList<int>) or have higher performance than the ones in System.Linq.Enumerable. More...


Source file:

Remarks

This class enhances LINQ-to-Objects with extension methods that preserve the interface (e.g. Take(IList<int>) returns a struct that implements IList<int>) or have higher performance than the ones in System.Linq.Enumerable.

Helpful article: http://core.loyc.net/essentials/linq-to-lists.html

For example, the Enumerable.Last<T> extension method scans the entire list before returning the last item, while Last<T>(IReadOnlyList<T>) and Last<T>(IList<T>) simply return the last item directly.

Static Public Member Functions

static int Count< T > (this IReadOnlyCollection< T > list)
 
static int Count< T > (this INegListSource< T > list)
 
static T FirstOrDefault< T > (this IListSource< T > list)
 
static T FirstOrDefault< T > (this IListSource< T > list, T defaultValue)
 
static T Last< T > (this IReadOnlyList< T > list)
 Gets the last item from the list (at list.Max). More...
 
static T LastOrDefault< T > (this IReadOnlyList< T > list, T defaultValue=default(T))
 Gets the last item from the list (Count - 1), or defaultValue if the list is empty. More...
 
static T Last< T > (this IListAndListSource< T > list)
 
static T Last< T > (this INegListSource< T > list)
 Gets the last item from the list (at list.Max). More...
 
static T LastOrDefault< T > (this INegListSource< T > list, T defaultValue=default(T))
 Gets the last item from the list (at list.Max), or defaultValue if the list is empty. More...
 
static Slice_< T > Skip< T > (this IListSource< T > list, int start)
 Skips the specified number of elements immediately and returns a slice of part of the list that remains, or an empty slice if start is greater than or equal to the list.Count. More...
 
static Slice_< T > Take< T > (this IListSource< T > list, int count)
 Returns a slice of the specified number of elements from the beginning of the list, or a slice of the entire list if count is greater than or equal to the list.Count. More...
 
static ListSlice< T > Skip< T > (this IListAndListSource< T > list, int start)
 Skips the specified number of elements immediately and returns a slice of part of the list that remains, or an empty slice if start is greater than or equal to the list.Count. More...
 
static ListSlice< T > Take< T > (this IListAndListSource< T > list, int count)
 Returns a slice of the specified number of elements from the beginning of the list, or a slice of the entire list if count is greater than or equal to the list.Count. More...
 
static NegListSlice< T > Skip< T > (this INegListSource< T > list, int count)
 
static NegListSlice< T > Take< T > (this INegListSource< T > list, int count)
 
static Slice_< T > TakeNowWhile< T > (this IListSource< T > list, Func< T, bool > predicate)
 Returns a slice of the initial elements of the list that meet the provided criteria. The word "now" is added to the name because unlike Enumerable.TakeWhile, this method scans the list immediately. More...
 
static Slice_< T > SkipNowWhile< T > (this IListSource< T > list, Func< T, bool > predicate)
 Returns a slice without the initial elements of the list that meet the specified criteria. The word "now" is added to the name because unlike Enumerable.SkipWhile, this method scans the list immediately. More...
 
static NegListSlice< T > TakeNowWhile< T > (this INegListSource< T > list, Func< T, bool > predicate)
 Returns a slice of the initial elements of the list that meet the provided criteria. The word "now" is added to the name because unlike Enumerable.TakeWhile, this method scans the list immediately. More...
 
static NegListSlice< T > SkipNowWhile< T > (this INegListSource< T > list, Func< T, bool > predicate)
 Returns a slice without the initial elements of the list that meet the specified criteria. The word "now" is added to the name because unlike Enumerable.SkipWhile, this method scans the list immediately. More...
 
static T[] ToArray< T > (this IReadOnlyList< T > c)
 Copies the contents of a list to an array. More...
 
static T[] ToArray< T > (this IListAndListSource< T > c)
 
static T[] ToArray< T > (this INegListSource< T > c)
 Copies the contents of an INegListSource<T> to an array. More...
 
static SelectListSource< IListSource< T >, T, TResult > Select< T, TResult > (this IListSource< T > source, Func< T, TResult > selector)
 
static SelectReadOnlyList< IReadOnlyList< T >, T, TResult > Select< T, TResult > (this IReadOnlyList< T > list, Func< T, TResult > selector)
 
static SelectReadOnlyCollection< IReadOnlyCollection< T >, T, TResult > Select< T, TResult > (this IReadOnlyCollection< T > list, Func< T, TResult > selector)
 
static T[] ConcatNow< T > (this T[] a, T[] b)
 
static T[] ConcatNow< T > (this IReadOnlyList< T > a, IReadOnlyList< T > b)
 
static ReversedListSource< T > Reverse< T > (this IListSource< T > c)
 Returns a reversed view of a read-only list. More...
 
static ReversedList< T > Reverse< T > (this IList< T > list)
 Returns an editable reversed view of a list. More...
 
static ReversedList< T > Reverse< T > (this IListAndListSource< T > list)
 
static bool SequenceEqual< TSource > (this IReadOnlyCollection< TSource > first, IReadOnlyCollection< TSource > second)
 

Member Function Documentation

◆ Last< T >() [1/2]

static T Loyc.Collections.LinqToLists.Last< T > ( this INegListSource< T >  list)
inlinestatic

Gets the last item from the list (at list.Max).

Exceptions
EmptySequenceExceptionThe list is empty

References Loyc.Collections.INegListSource< out out T >.Max, and Loyc.Collections.INegListSource< out out T >.Min.

◆ Last< T >() [2/2]

static T Loyc.Collections.LinqToLists.Last< T > ( this IReadOnlyList< T >  list)
inlinestatic

Gets the last item from the list (at list.Max).

Exceptions
EmptySequenceExceptionThe list is empty

◆ LastOrDefault< T >() [1/2]

static T Loyc.Collections.LinqToLists.LastOrDefault< T > ( this INegListSource< T >  list,
defaultValue = default(T) 
)
inlinestatic

Gets the last item from the list (at list.Max), or defaultValue if the list is empty.

References Loyc.Collections.INegListSource< out out T >.Max, and Loyc.Collections.INegListSource< out out T >.Min.

◆ LastOrDefault< T >() [2/2]

static T Loyc.Collections.LinqToLists.LastOrDefault< T > ( this IReadOnlyList< T >  list,
defaultValue = default(T) 
)
inlinestatic

Gets the last item from the list (Count - 1), or defaultValue if the list is empty.

◆ Reverse< T >() [1/2]

static ReversedList<T> Loyc.Collections.LinqToLists.Reverse< T > ( this IList< T >  list)
static

Returns an editable reversed view of a list.

This was originally named ReverseView. Changed to Reverse to match Linq's Reverse(IEnumerable).

◆ Reverse< T >() [2/2]

static ReversedListSource<T> Loyc.Collections.LinqToLists.Reverse< T > ( this IListSource< T >  c)
inlinestatic

Returns a reversed view of a read-only list.

This was originally named ReverseView. Changed to Reverse to match Linq's Reverse(IEnumerable).

◆ Skip< T >() [1/2]

static ListSlice<T> Loyc.Collections.LinqToLists.Skip< T > ( this IListAndListSource< T >  list,
int  start 
)
inlinestatic

Skips the specified number of elements immediately and returns a slice of part of the list that remains, or an empty slice if start is greater than or equal to the list.Count.

◆ Skip< T >() [2/2]

static Slice_<T> Loyc.Collections.LinqToLists.Skip< T > ( this IListSource< T >  list,
int  start 
)
inlinestatic

Skips the specified number of elements immediately and returns a slice of part of the list that remains, or an empty slice if start is greater than or equal to the list.Count.

◆ SkipNowWhile< T >() [1/2]

static Slice_<T> Loyc.Collections.LinqToLists.SkipNowWhile< T > ( this IListSource< T >  list,
Func< T, bool >  predicate 
)
inlinestatic

Returns a slice without the initial elements of the list that meet the specified criteria. The word "now" is added to the name because unlike Enumerable.SkipWhile, this method scans the list immediately.

Example: new[] { 24, 28, 2, 12, 11 }.SkipNowWhile(n => n > 10) returns a slice (not a copy) of the last 2 elements.

◆ SkipNowWhile< T >() [2/2]

static NegListSlice<T> Loyc.Collections.LinqToLists.SkipNowWhile< T > ( this INegListSource< T >  list,
Func< T, bool >  predicate 
)
inlinestatic

Returns a slice without the initial elements of the list that meet the specified criteria. The word "now" is added to the name because unlike Enumerable.SkipWhile, this method scans the list immediately.

Example: new[] { 24, 28, 2, 12, 11 }.SkipNowWhile(n => n > 10) returns a slice (not a copy) of the last 2 elements.

References Loyc.Collections.INegListSource< out out T >.Min.

◆ Take< T >() [1/2]

static ListSlice<T> Loyc.Collections.LinqToLists.Take< T > ( this IListAndListSource< T >  list,
int  count 
)
inlinestatic

Returns a slice of the specified number of elements from the beginning of the list, or a slice of the entire list if count is greater than or equal to the list.Count.

◆ Take< T >() [2/2]

static Slice_<T> Loyc.Collections.LinqToLists.Take< T > ( this IListSource< T >  list,
int  count 
)
inlinestatic

Returns a slice of the specified number of elements from the beginning of the list, or a slice of the entire list if count is greater than or equal to the list.Count.

◆ TakeNowWhile< T >() [1/2]

static Slice_<T> Loyc.Collections.LinqToLists.TakeNowWhile< T > ( this IListSource< T >  list,
Func< T, bool >  predicate 
)
inlinestatic

Returns a slice of the initial elements of the list that meet the provided criteria. The word "now" is added to the name because unlike Enumerable.TakeWhile, this method scans the list immediately.

Example: new[] { 13, 16, 19, 2, 11, 12 }.TakeNowWhile(n => n > 10) returns a slice (not a copy) of the first 3 elements.

◆ TakeNowWhile< T >() [2/2]

static NegListSlice<T> Loyc.Collections.LinqToLists.TakeNowWhile< T > ( this INegListSource< T >  list,
Func< T, bool >  predicate 
)
inlinestatic

Returns a slice of the initial elements of the list that meet the provided criteria. The word "now" is added to the name because unlike Enumerable.TakeWhile, this method scans the list immediately.

Example: new[] { 13, 16, 19, 2, 11, 12 }.TakeNowWhile(n => n > 10) returns a slice (not a copy) of the first 3 elements.

References Loyc.Collections.INegListSource< out out T >.Min.

◆ ToArray< T >() [1/2]

static T [] Loyc.Collections.LinqToLists.ToArray< T > ( this INegListSource< T >  c)
inlinestatic

Copies the contents of an INegListSource<T> to an array.

References Loyc.Collections.INegListSource< out out T >.Min.

◆ ToArray< T >() [2/2]

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

Copies the contents of a list to an array.