MoreEnumerable.Partition<T, TResult> Method (IEnumerable<T>, Func<T, Boolean>, Func<IEnumerable<T>, IEnumerable<T>, TResult>) |
Partitions or splits a sequence in two using a predicate and then
projects a result from the two.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntaxpublic static TResult Partition<T, TResult>(
this IEnumerable<T> source,
Func<T, bool> predicate,
Func<IEnumerable<T>, IEnumerable<T>, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function Partition(Of T, TResult) (
source As IEnumerable(Of T),
predicate As Func(Of T, Boolean),
resultSelector As Func(Of IEnumerable(Of T), IEnumerable(Of T), TResult)
) As TResult
public:
[ExtensionAttribute]
generic<typename T, typename TResult>
static TResult Partition(
IEnumerable<T>^ source,
Func<T, bool>^ predicate,
Func<IEnumerable<T>^, IEnumerable<T>^, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member Partition :
source : IEnumerable<'T> *
predicate : Func<'T, bool> *
resultSelector : Func<IEnumerable<'T>, IEnumerable<'T>, 'TResult> -> 'TResult
Parameters
- source
- Type: System.Collections.Generic.IEnumerable<T>
The source sequence. - predicate
- Type: System.Func<T, Boolean>
The predicate function. - resultSelector
- Type: System.Func<IEnumerable<T>, IEnumerable<T>, 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
Type:
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
IEnumerable<T>. 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).
Examplesvar (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.
See Also