Partition
Splits the collection into two collections, containing the elements for which the given predicate returns true and false respectively.
Element order is preserved in both of the created collections.
| Parameters | Returns |
|---|---|
Func<T, bool> predicate IEnumerable<T> source |
(IEnumerable<T> Trues, IEnumerable<T> Falses) |
Usage
Splitting even and odd numbers
//IEnumerable<int> source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
var (resultEvens, resultOdds) =
source.Partition(value => value % 2 == 0)
//resultEvens = { 2, 4, 6, 8, 10 }
//resultOdds = { 1, 3, 5, 7, 9 }