IEnumerableExtensions¶
Namespace:
SideXP.Core
Extension functions for IEnumerable1` instances.
Methods¶
Join(IEnumerable, string)¶
Joins the items in the given collection into a single string using a separator.
Parameters
enumerable: The collection to pack into a single string.separator: The character(s) that separates each elements in the output text.
Returns
Returns the processed string.
Remarks
Each item is represented by its ToString value (null items are represented as empty strings).
Join<T>(IEnumerable<T>, string, MapPredicateDelegate<T, string>)¶
public static string Join<T>(IEnumerable<T> enumerable, string separator, MapPredicateDelegate<T, string> mapFunc)
Joins the items in the given collection into a single string using a separator.
Parameters
mapFunc: The function called for every item to convert it into a string.enumerable: The collection to pack into a single string.separator: The character(s) that separates each elements in the output text.
Returns
Returns the processed string.
Remarks
Each item is represented by its ToString value (null items are represented as empty strings).
Map<TInput, TOutput>(IEnumerable<TInput>, MapPredicateDelegate<TInput, TOutput>)¶
public static TOutput[] Map<TInput, TOutput>(IEnumerable<TInput> enumerable, MapPredicateDelegate<TInput, TOutput> mapFunc)
Creates a new array populated with the results of calling a given function every item in the given collection.
Type parameters
TInput: The type of an item in the input collection.TOutput: The type of the output data when calling the action function on each item.
Parameters
enumerable: The collection you want to "map".mapFunc: The function to call to provide a data for each item.
Returns
Returns the mapped items array.
Convert<T>(IEnumerable<object>)¶
Converts all the items of a given collection into a given type.
Type parameters
T: The type to which you want to convert every items.
Parameters
enumerable: The collection you want to convert.
Returns
Returns the converted items array.
Filter<TSource, TTarget>(IEnumerable<TSource>, bool)¶
public static TTarget[] Filter<TSource, TTarget>(IEnumerable<TSource> source, bool includeDerivedTypes = false)
Filters all the objects from a collection that have a given type.
Type parameters
TSource: The type of the source collection.TTarget: The type of the objects to filter.
Parameters
source: The source collection.includeDerivedTypes: If enabled, this function will filter all the objects that have the expected type OR the objects that derive from it.
Returns
Returns the filtered elements.
Remarks
By default, only the objects whose runtime type is exactly TTarget are kept. Enable includeDerivedTypes to also keep the objects that derive from it. Null items are always skipped.
PickRandom<T>(IEnumerable<T>)¶
Gets a random element of a given collection.
Type parameters
T: The type of the source collection.
Parameters
source: The source collection.
Returns
Returns the picked element, or a default value if the collection is empty.