PartitionExtensionPartitionT, TResult(IEnumerableT, FuncT, Boolean, FuncIEnumerableT, IEnumerableT, TResult) Method

Partitions or splits a sequence in two using a predicate and then projects a result from the two.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static TResult Partition<T, TResult>(
	this IEnumerable<T> source,
	Func<T, bool> predicate,
	Func<IEnumerable<T>, IEnumerable<T>, TResult> resultSelector
)

Parameters

source  IEnumerableT
The source sequence.
predicate  FuncT, Boolean
The predicate function.
resultSelector  FuncIEnumerableT, IEnumerableT, TResult
Function that projects the result from sequences of elements that satisfy the predicate and those that do not, respectively, passed as arguments.

Type Parameters

T
Type of source elements.
TResult
Type of the result.

Return Value

TResult
The return value from resultSelector.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Example

C#
var (evens, odds) =
    Enumerable.Range(0, 10)
              .Partition(x => x % 2 == 0, ValueTuple.Create);
The evens variable, when iterated over, will yield 0, 2, 4, 6 and then 8. The odds variable, when iterated over, will yield 1, 3, 5, 7 and then 9.

Exceptions

ArgumentNullExceptionsource, predicate, or resultSelector is .

See Also