A collection of extension methods for IEnumerable<T>, List<T> and arrays.
More...
|
static TElement | FirstByGeneratedValue< TElement, TValue > (this IEnumerable< TElement > list, Func< TElement, TValue > valueConverter, Predicate< TValue > predicateValue=null) |
| Takes a collection, generates values from the items and and returns the item with the lowest generated value. Useful for example to find the closest item. Reverse the generated values to find the item with the highest generated value. More...
|
|
static TElement | Nearest< TElement > (this IEnumerable< TElement > list, Vector3 referencePoint, float minDistance=0, float maxDistance=float.PositiveInfinity) |
| Returns the component nearest to the referencePoint and in minimum/maximum range. More...
|
|
static void | Shuffle< T > (this T[] list) |
| Shuffles an array in place. More...
|
|
static void | Shuffle< T > (this List< T > list) |
| Shuffles a list in place. More...
|
|
static T | RandomElement< T > (this T[] array) |
| Returns a random element from the array. More...
|
|
static T | RandomElement< T > (this List< T > list) |
| Returns a random element from the list. More...
|
|
static string | ToOneLineString< T > (this IEnumerable< T > list, string separator=", ", string encapsulate="\) |
| Calls ToString() on every element of the list, puts [encapsulate] directly before and after the result and then concatenates the results with [seperator] between them. More...
|
|
A collection of extension methods for IEnumerable<T>, List<T> and arrays.
§ FirstByGeneratedValue< TElement, TValue >()
static TElement UnityUtilities.LINQExtensions.FirstByGeneratedValue< TElement, TValue > |
( |
this IEnumerable< TElement > |
list, |
|
|
Func< TElement, TValue > |
valueConverter, |
|
|
Predicate< TValue > |
predicateValue = null |
|
) |
| |
|
static |
Takes a collection, generates values from the items and and returns the item with the lowest generated value. Useful for example to find the closest item. Reverse the generated values to find the item with the highest generated value.
This returns the same as list.Where(element => predicateValue(valueConverter(element))).OrderBy(valueConverter).First(), but it a) doesn't order the whole list and b) doesn't call valueConverted more than once per element.
- Template Parameters
-
TElement | The collection element type. |
TValue | The generated value type. |
- Parameters
-
list | The list of elements. |
valueConverter | The method to convert an element to a generated value used for ordering. |
predicateValue | A predicate testing whether the generated value is permitted. If true, the element is used; if false, the element is skipped. |
- Returns
- The first element by the generated value in order that succeeded the predicateValue test.
§ Nearest< TElement >()
static TElement UnityUtilities.LINQExtensions.Nearest< TElement > |
( |
this IEnumerable< TElement > |
list, |
|
|
Vector3 |
referencePoint, |
|
|
float |
minDistance = 0 , |
|
|
float |
maxDistance = float.PositiveInfinity |
|
) |
| |
|
static |
Returns the component nearest to the referencePoint and in minimum/maximum range.
- Template Parameters
-
TElement | The collection element type. Needs to be a subclass of Component. |
- Parameters
-
list | The list of components. |
referencePoint | A reference point to get the distance from. |
minDistance | Optional: The minimum distance. |
maxDistance | Optional: The maximum distance. |
- Returns
- The element nearest to the referencePoint and in minimum/maximum range.
§ RandomElement< T >() [1/2]
static T UnityUtilities.LINQExtensions.RandomElement< T > |
( |
this T [] |
array | ) |
|
|
static |
Returns a random element from the array.
- Template Parameters
-
- Parameters
-
array | The array to return an element from. |
- Returns
- A random element from the array.
§ RandomElement< T >() [2/2]
static T UnityUtilities.LINQExtensions.RandomElement< T > |
( |
this List< T > |
list | ) |
|
|
static |
Returns a random element from the list.
- Template Parameters
-
- Parameters
-
list | The list to return an element from. |
- Returns
- A random element from the list.
§ Shuffle< T >() [1/2]
static void UnityUtilities.LINQExtensions.Shuffle< T > |
( |
this T [] |
list | ) |
|
|
static |
Shuffles an array in place.
- Template Parameters
-
- Parameters
-
list | The array to shuffle. |
§ Shuffle< T >() [2/2]
static void UnityUtilities.LINQExtensions.Shuffle< T > |
( |
this List< T > |
list | ) |
|
|
static |
Shuffles a list in place.
- Template Parameters
-
- Parameters
-
§ ToOneLineString< T >()
static string UnityUtilities.LINQExtensions.ToOneLineString< T > |
( |
this IEnumerable< T > |
list, |
|
|
string |
separator = ", " , |
|
|
string |
encapsulate = "\"" |
|
) |
| |
|
static |
Calls ToString() on every element of the list, puts [encapsulate] directly before and after the result and then concatenates the results with [seperator] between them.
- Template Parameters
-
T | The collection element type. |
- Parameters
-
list | The collection to concatenate. |
separator | The seperator between entries. |
encapsulate | The string to put directly before and after every item. |
- Returns
- A string containing the ToString() results of all items.
The documentation for this class was generated from the following file:
- LINQExtensions/LINQExtensions.cs