Class EnumerableExtensions
- Namespace
- LfrlAnvil.Functional.Extensions
- Assembly
- LfrlAnvil.Functional.dll
Contains IEnumerable<T> extension methods.
public static class EnumerableExtensions
- Inheritance
-
EnumerableExtensions
- Inherited Members
Methods
Partition<T>(IEnumerable<Erratic<T>>)
Partitions the provided source
into separate collections that contain values and errors.
[Pure]
public static (List<T> Values, List<Exception> Errors) Partition<T>(this IEnumerable<Erratic<T>> source)
Parameters
source
IEnumerable<Erratic<T>>Source collection.
Returns
Type Parameters
T
Value type.
Partition<T1, T2>(IEnumerable<Either<T1, T2>>)
Partitions the provided source
into separate collections that contain first and second values.
[Pure]
public static (List<T1> First, List<T2> Second) Partition<T1, T2>(this IEnumerable<Either<T1, T2>> source)
Parameters
source
IEnumerable<Either<T1, T2>>Source collection.
Returns
Type Parameters
T1
First either type.
T2
Second either type.
SelectErrors<T>(IEnumerable<Erratic<T>>)
Filters out elements with values from the provided source
.
[Pure]
public static IEnumerable<Exception> SelectErrors<T>(this IEnumerable<Erratic<T>> source)
Parameters
source
IEnumerable<Erratic<T>>Source collection.
Returns
- IEnumerable<Exception>
New IEnumerable<T> with elements with values filtered out.
Type Parameters
T
Value type.
SelectFirst<T1, T2>(IEnumerable<Either<T1, T2>>)
Filters out elements with second value from the provided source
.
[Pure]
public static IEnumerable<T1> SelectFirst<T1, T2>(this IEnumerable<Either<T1, T2>> source)
Parameters
source
IEnumerable<Either<T1, T2>>Source collection.
Returns
- IEnumerable<T1>
New IEnumerable<T> with elements with second value filtered out.
Type Parameters
T1
First either type.
T2
Second either type.
SelectSecond<T1, T2>(IEnumerable<Either<T1, T2>>)
Filters out elements with first value from the provided source
.
[Pure]
public static IEnumerable<T2> SelectSecond<T1, T2>(this IEnumerable<Either<T1, T2>> source)
Parameters
source
IEnumerable<Either<T1, T2>>Source collection.
Returns
- IEnumerable<T2>
New IEnumerable<T> with elements with first value filtered out.
Type Parameters
T1
First either type.
T2
Second either type.
SelectValues<T>(IEnumerable<Erratic<T>>)
Filters out elements with errors from the provided source
.
[Pure]
public static IEnumerable<T> SelectValues<T>(this IEnumerable<Erratic<T>> source)
Parameters
source
IEnumerable<Erratic<T>>Source collection.
Returns
- IEnumerable<T>
New IEnumerable<T> with elements with errors filtered out.
Type Parameters
T
Value type.
SelectValues<T>(IEnumerable<Maybe<T>>)
Filters out None elements from the provided source
.
[Pure]
public static IEnumerable<T> SelectValues<T>(this IEnumerable<Maybe<T>> source) where T : notnull
Parameters
source
IEnumerable<Maybe<T>>Source collection.
Returns
- IEnumerable<T>
New IEnumerable<T> with None elements filtered out.
Type Parameters
T
Value type.
TryAggregate<T>(IEnumerable<T>, Func<T, T, T>)
Attempts to compute an aggregation for the provided source
.
[Pure]
public static Maybe<T> TryAggregate<T>(this IEnumerable<T> source, Func<T, T, T> func) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
func
Func<T, T, T>Aggregator delegate.
Returns
Type Parameters
T
Collection element type.
TryElementAt<T>(IEnumerable<T>, int)
Attempts to get an element at the specified index
in the provided source
.
[Pure]
public static Maybe<T> TryElementAt<T>(this IEnumerable<T> source, int index) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
index
int0-based position of an element to find.
Returns
- Maybe<T>
New Maybe<T> instance equivalent to the element at the specified position or None when
index
is not in [0,source
count) range.
Type Parameters
T
Collection element type.
TryFirst<T>(IEnumerable<T>)
Attempts to get the first element in the provided source
.
[Pure]
public static Maybe<T> TryFirst<T>(this IEnumerable<T> source) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection element type.
TryLast<T>(IEnumerable<T>)
Attempts to get the last element in the provided source
.
[Pure]
public static Maybe<T> TryLast<T>(this IEnumerable<T> source) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection element type.
TryMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>)
Attempts to find an element with the maximum value specified by the selector
in the provided source
using the Default comparer.
[Pure]
public static Maybe<T1> TryMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector) where T1 : notnull
Parameters
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
TryMaxBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>)
Attempts to find an element with the maximum value specified by the selector
in the provided source
.
[Pure]
public static Maybe<T1> TryMaxBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer) where T1 : notnull
Parameters
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
TryMax<T>(IEnumerable<T>)
Attempts to find the maximum value in the provided source
by using the Default comparer.
[Pure]
public static Maybe<T> TryMax<T>(this IEnumerable<T> source) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection element type.
TryMax<T>(IEnumerable<T>, IComparer<T>)
Attempts to find the maximum value in the provided source
.
[Pure]
public static Maybe<T> TryMax<T>(this IEnumerable<T> source, IComparer<T> comparer) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
T
Collection element type.
TryMinBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>)
Attempts to find an element with the minimum value specified by the selector
in the provided source
using the Default comparer.
[Pure]
public static Maybe<T1> TryMinBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector) where T1 : notnull
Parameters
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
TryMinBy<T1, T2>(IEnumerable<T1>, Func<T1, T2>, IComparer<T2>)
Attempts to find an element with the minimum value specified by the selector
in the provided source
.
[Pure]
public static Maybe<T1> TryMinBy<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector, IComparer<T2> comparer) where T1 : notnull
Parameters
source
IEnumerable<T1>Source collection.
selector
Func<T1, T2>Selector of a value to use for comparison.
comparer
IComparer<T2>Comparer to use for value comparison.
Returns
Type Parameters
T1
Collection element type.
T2
Value type used for comparison.
TryMin<T>(IEnumerable<T>)
Attempts to find the minimum value in the provided source
by using the Default comparer.
[Pure]
public static Maybe<T> TryMin<T>(this IEnumerable<T> source) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
Returns
Type Parameters
T
Collection element type.
TryMin<T>(IEnumerable<T>, IComparer<T>)
Attempts to find the minimum value in the provided source
.
[Pure]
public static Maybe<T> TryMin<T>(this IEnumerable<T> source, IComparer<T> comparer) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
comparer
IComparer<T>Comparer to use for element comparison.
Returns
Type Parameters
T
Collection element type.
TrySingle<T>(IEnumerable<T>)
Attempts to get the only element in the provided source
.
[Pure]
public static Maybe<T> TrySingle<T>(this IEnumerable<T> source) where T : notnull
Parameters
source
IEnumerable<T>Source collection.
Returns
- Maybe<T>
New Maybe<T> instance equivalent to the only element or None when
source
is empty or contains more than 1 element.
Type Parameters
T
Collection element type.