Extension methods and helper methods for List<T>, IList<T>, IReadOnlyList<T>, arrays, IListSource<T>, and for related mutable interfaces such as IArray<T>.
More...
Extension methods and helper methods for List<T>, IList<T>, IReadOnlyList<T>, arrays, IListSource<T>, and for related mutable interfaces such as IArray<T>.
Extension methods that only apply to Loyc's new interfaces, or adapt a list to those interfaces, will go in LCExt instead.
The source code for adapter extension methods such as the Slice() method for arrays, which returns an ArraySlice<T> adapter, is now placed in the source file for each adapter class (e.g. ArraySlice.cs) to make it easier to create custom versions of Loyc.Essentials with parts removed.
|
static ROLSlice< IReadOnlyList< T >, T > | Slice< T > (this IReadOnlyList< T > list, int start, int count=int.MaxValue) |
|
static IRange< T > | AsRange< T > (this IListSource< T > list) |
|
static IRange< T > | AsRange< T > (this IRange< T > list) |
|
static int | BinarySearch< T > (this IReadOnlyList< T > list, T value) |
|
static int | BinarySearch< T > (this IReadOnlyList< T > list, T value, IComparer< T > comparer) |
|
static int | BinarySearch< T > (this IReadOnlyList< T > list, T find, Comparison< T > compare) |
|
static int | BinarySearch2< T, K > (this IReadOnlyList< T > list, K find, Func< T, K, int > compare, bool lowerBound=true) |
|
static int | BinarySearch< T > (this IListAndListSource< T > list, T value) |
|
static int | BinarySearch< T > (this IListAndListSource< T > list, T value, IComparer< T > comparer) |
|
static int | BinarySearch< T > (this IListAndListSource< T > list, T value, Comparison< T > compare) |
|
static int | BinarySearch2< T, K > (this IListAndListSource< T > list, K value, Func< T, K, int > compare, bool lowerBound=true) |
|
static void | CopyTo< T > (this IReadOnlyCollection< T > c, T[] array, int arrayIndex) |
|
static T | TryGet< T > (this IReadOnlyList< T > list, int index, T defaultValue) |
|
static Maybe< T > | TryGet< T > (this IReadOnlyList< T > list, int index) |
|
static void | RemoveRange< T > (this IList< T > list, int index, int count) |
| Removes count items from list starting at the specified index . More...
|
|
static void | Resize< T > (this List< T > list, int newSize) |
| Resizes a list by removing items from the list (if it is too long) or adding default(T) values to the end (if it is too short). More...
|
|
static void | Resize< T > (this IList< T > list, int newSize) |
| Resizes a list by removing items from the list (if it is too long) or adding default(T) values to the end (if it is too short). More...
|
|
static void | MaybeEnlarge< T > (this List< T > list, int minSize) |
|
static void | MaybeEnlarge< T > (this IList< T > list, int minSize) |
|
static bool | AddIfNotPresent< TList, T > (this TList list, T item) |
|
static IEnumerable< Pair< A, B > > | Zip< A, B > (this IEnumerable< A > a, IEnumerable< B > b) |
| Returns a sequence of length Min(a.Count(), b.Count()) of items from a and b paired together. The output is produced lazily, so infinite input sequences are supported. More...
|
|
static IEnumerable< Pair< A, B > > | ZipLeft< A, B > (this IEnumerable< A > a, IEnumerable< B > b, B defaultB) |
| Returns a sequence that has the same length as the first sequence, with items from the first and second sequence paired together. More...
|
|
static IEnumerable< C > | ZipLeft< A, B, C > (this IEnumerable< A > a, IEnumerable< B > b, B defaultB, Func< A, B, C > resultSelector) |
| An alternate version of ZipLeft<A, B>(IEnumerable<A>, IEnumerable<B>, B) in which a user-defined function is used to combine the items from the two lists. More...
|
|
static IEnumerable< Pair< A, B > > | ZipLonger< A, B > (this IEnumerable< A > a, IEnumerable< B > b) |
| Returns a sequence as long as the longer of two sequences. Items from the first and second sequence are initially paired together, and when one sequence ends, the other sequence's remaining values are paired with a default value. More...
|
|
static IEnumerable< Pair< A, B > > | ZipLonger< A, B > (this IEnumerable< A > a, IEnumerable< B > b, A defaultA, B defaultB) |
| Returns a sequence as long as the longer of two sequences. Items from the first and second sequence are initially paired together, and when one sequence ends, the other sequence's remaining values are paired with a default value provided as a parameter. More...
|
|
static IEnumerable< C > | ZipLonger< A, B, C > (this IEnumerable< A > a, IEnumerable< B > b, A defaultA, B defaultB, Func< A, B, C > resultSelector) |
| An alternate version of ZipLonger<A, B>(IEnumerable<A>, IEnumerable<B>, A, B) in which a user-defined function is used to combine the items from the two lists. More...
|
|
static int[] | RangeArray (int count) |
| Returns an array of Length count containing the numbers 0 through count-1 . More...
|
|
static void | Sort< T > (this IList< T > list) |
|
static void | Sort< T > (this IList< T > list, Comparison< T > comp) |
|
static void | Sort< T > (this IList< T > list, int index, int count, Comparison< T > comp) |
| Performs a quicksort using a Comparison function. More...
|
|
static void | StableSort< T > (this IList< T > list, Comparison< T > comp) |
| Performs a stable sort, i.e. a sort that preserves the relative order of items that compare equal. More...
|
|
static void | StableSort< T > (this IList< T > list) |
|
static ListSlice< T > | SortLowestK< T > (this IList< T > list, int k) |
| Uses a partial quicksort, known as "quickselect", to find and sort the lowest k elements in a list. More...
|
|
static ListSlice< T > | SortLowestK< T > (this IList< T > list, int k, Comparison< T > comp) |
|
static ListSlice< T > | SortLowestK< T > (this IList< T > list, int index, int count, int k, Comparison< T > comp) |
|
static ListSlice< T > | SortLowestKStable< T > (this IList< T > list, int k) |
| A stable version of SortLowestK<T>(IList<T>,int). This means that when k>1 and adjacent results at the beginning of list compare equal, they keep the same order that they had originally. More...
|
|
static ListSlice< T > | SortLowestKStable< T > (this IList< T > list, int k, Comparison< T > comp) |
|
static void | InsertionSort< T > (this IList< T > array, int index, int count, Comparison< T > comp) |
| Performs an insertion sort. More...
|
|
static bool | SortPair< T > (this IList< T > list, int i, int j, Comparison< T > comp) |
| Sorts two items to ensure that list[i] is less than list[j]. More...
|
|
static void | Swap< T > (this IList< T > list, int i, int j) |
| Swaps list[i] with list[j]. More...
|
|
static void | Swap< T > (this IArray< T > list, int i, int j) |
|
static void | Randomize< T > (this IList< T > list) |
|
static void | Randomize< T > (this T[] list) |
|
static T[] | Randomized< T > (this IReadOnlyList< T > list) |
| Quickly makes a copy of a list, as an array, in random order. More...
|
|
static R[] | SelectArray< T, R > (this T[] input, Func< T, R > selector) |
| Maps an array to another array of the same length. More...
|
|
static R[] | SelectArray< T, R > (this IReadOnlyList< T > input, Func< T, R > selector) |
| Maps a list to an array of the same length. More...
|
|
static R[] | SelectArray< T, R > (this IListAndListSource< T > input, Func< T, R > selector) |
| Maps a list to an array of the same length. More...
|
|
static int | RemoveAll< T > (this IList< T > list, Predicate< T > match) |
| Removes the all the elements that match the conditions defined by the specified predicate. More...
|
|
static void | ReverseInPlace< T > (this IList< T > list) |
|
static void | ReverseInPlace< T > (this IArray< T > list) |
|
static void | AddRange< T > (this IList< T > list, IEnumerable< T > range) |
|
static int | InsertRange< T > (this IList< T > list, int index, IReadOnlyCollection< T > source) |
|
static int | InsertRange< T > (this IList< T > list, int index, ICollection< T > source) |
|
static int | InsertRange< T > (this IList< T > list, int index, IListAndListSource< T > source) |
|
static int | InsertRange< T > (this IList< T > list, int index, ICollectionAndReadOnly< T > source) |
|
static int | InsertRange< T > (this IList< T > list, int index, int count, IEnumerable< T > source) |
|
static void | InsertRangeHelper< T > (IList< T > list, int index, int spaceNeeded) |
| Increases the list size by spaceNeeded and copies elements starting at list[index] "rightward" to make room for inserted elements that will be initialized by the caller. More...
|
|
static Repeated< T > | Repeat< T > (T value, int count) |
| Returns a helper object that stores one value, but acts like a read-only list that repeats the value the specified number of times. More...
|
|
static Repeated< T > | Single< T > (T value) |
| Returns a helper object that stores one value, but acts like a read-only list of one item. More...
|
|