PartitionExtensionPartitionT(IEnumerableT, FuncT, Boolean) Method
Partitions or splits a sequence in two using a predicate.
Namespace: MoreLinq.ExtensionsAssembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
public static (IEnumerable<T> True, IEnumerable<T> False) Partition<T>(
this IEnumerable<T> source,
Func<T, bool> predicate
)
<ExtensionAttribute>
Public Shared Function Partition(Of T) (
source As IEnumerable(Of T),
predicate As Func(Of T, Boolean)
) As (True As IEnumerable(Of T), False As IEnumerable(Of T))
public:
[ExtensionAttribute]
generic<typename T>
static ValueTuple<IEnumerable<T>^, IEnumerable<T>^> Partition(
IEnumerable<T>^ source,
Func<T, bool>^ predicate
)
[<ExtensionAttribute>]
static member Partition :
source : IEnumerable<'T> *
predicate : Func<'T, bool> -> ValueTuple<IEnumerable<'T>, IEnumerable<'T>>
- source IEnumerableT
- The source sequence.
- predicate FuncT, Boolean
- The predicate function.
- T
- Type of source elements.
ValueTupleIEnumerableT,
IEnumerableT
A tuple of elements satisfying the predicate and those that do not,
respectively.
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).
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.