Click or drag to resize

MoreEnumerablePartitionT Method (IEnumerableT, FuncT, Boolean)

Partitions or splits a sequence in two using a predicate.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax
public static (IEnumerable<T> True, IEnumerable<T> False, , , T1 , T2 ,  ,  ) Partition<T>(
	this IEnumerable<T> source,
	Func<T, bool> predicate
)

Parameters

source
Type: System.Collections.GenericIEnumerableT
The source sequence.
predicate
Type: SystemFuncT, Boolean
The predicate function.

Type Parameters

T
Type of source elements.

Return Value

Type: ValueTupleIEnumerableT, IEnumerableT
A tuple of elements staisfying the predicate and those that do not, respectively.

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).
Examples
var (evens, odds) =
    Enumerable.Range(0, 10).Partition(x => x % 2 == 0);
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.
See Also