Class SwiftExtensions
- Namespace
- SwiftCollections
- Assembly
- SwiftCollections.dll
Provides extension methods for collection manipulation and utility functions.
public static class SwiftExtensions
- Inheritance
-
SwiftExtensions
- Inherited Members
Methods
FromEnd<T>(SwiftList<T>, int)
Gets the element at the specified index from the end (1-based) from SwiftList.
public static T FromEnd<T>(this SwiftList<T> list, int reverseIndex)
Parameters
Returns
- T
Type Parameters
T
FromEnd<T>(IEnumerable<T>, int)
Gets the element at the specified index from the end (1-based). For example, FromEnd(1) returns the last item, FromEnd(2) returns second-to-last.
public static T FromEnd<T>(this IEnumerable<T> source, int reverseIndex)
Parameters
sourceIEnumerable<T>reverseIndexint
Returns
- T
Type Parameters
T
IsPopulatedSafe<T>(IEnumerable<T>)
Determines whether the collection is not null and contains any elements.
public static bool IsPopulatedSafe<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The collection to check.
Returns
- bool
True if the collection is not null and contains at least one element; otherwise, false.
Type Parameters
TThe type of elements in the collection.
IsPopulated<T>(IEnumerable<T>)
Determines whether a sequence contains any elements.
public static bool IsPopulated<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>The IEnumerable<T> to check for emptiness.
Returns
- bool
true if the source sequence contains any elements; otherwise, false.
Type Parameters
T
PopLast<T>(IEnumerable<T>)
Returns the last item in the sequence.
public static T PopLast<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>
Returns
- T
Type Parameters
T
Populate<T>(T[])
Populates an array with new instances of the specified type. The type must have a parameterless constructor.
public static T[] Populate<T>(this T[] array) where T : new()
Parameters
arrayT[]The array to populate.
Returns
- T[]
The populated array.
Type Parameters
TThe type of the elements in the array.
Populate<T>(T[], Func<int, T>)
Populates an array with values generated by a provider function that accepts the current index.
public static T[] Populate<T>(this T[] array, Func<int, T> provider)
Parameters
arrayT[]The array to populate.
providerFunc<int, T>A function that generates a value for each element based on its index.
Returns
- T[]
The populated array.
Type Parameters
TThe type of the elements in the array.
Populate<T>(T[], Func<T>)
Populates an array with values generated by a specified provider function.
public static T[] Populate<T>(this T[] array, Func<T> provider)
Parameters
arrayT[]The array to populate.
providerFunc<T>A function that generates a value for each element in the array.
Returns
- T[]
The populated array.
Type Parameters
TThe type of the elements in the array.
SecondToLast<T>(IEnumerable<T>)
Returns the second-to-last item in the sequence.
public static T SecondToLast<T>(this IEnumerable<T> source)
Parameters
sourceIEnumerable<T>
Returns
- T
Type Parameters
T
ShuffleInPlace<T>(IList<T>, Random)
Shuffles the elements of the list in place using the specified random number generator.
public static void ShuffleInPlace<T>(this IList<T> list, Random rng)
Parameters
Type Parameters
TThe type of elements in the list.
Shuffle<T>(IEnumerable<T>, Random)
An iterator that yields the elements of the source collection in a random order using the specified random number generator.
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng)
Parameters
sourceIEnumerable<T>The collection to shuffle.
rngRandomThe random number generator to use for shuffling.
Returns
- IEnumerable<T>
An iterator that yields the shuffled elements.
Type Parameters
TThe type of elements in the collection.
SkipFromEnd<T>(IEnumerable<T>, int)
Bypasses a specified number of elements from the end and then returns the remaining elements.
public static IEnumerable<T> SkipFromEnd<T>(this IEnumerable<T> source, int count)
Parameters
sourceIEnumerable<T>countint
Returns
- IEnumerable<T>
Type Parameters
T
TryIndex<T>(T[], int, out T)
Attempts to retrieve an element from the array at the specified index. Returns true if the index is valid and the element is retrieved; otherwise, returns false.
public static bool TryIndex<T>(this T[] array, int index, out T result)
Parameters
arrayT[]The array from which to retrieve the element.
indexintThe index of the element to retrieve.
resultTWhen this method returns, contains the element at the specified index if the index is valid; otherwise, the default value for the type of the element.
Returns
- bool
True if the element at the specified index was retrieved successfully; otherwise, false.
Type Parameters
TThe type of elements in the array.