Bifurcate - Kalkwst/Risotto GitHub Wiki
Splits the values of the source sequence into two groups, based on the result of the given filtering function.
In this page
Overload | Description |
---|---|
Bifurcate(Func<TSource, bool> fn) | Splits the values of the source sequence into two groups, based on the result of the given filtering function. |
Splits the values of the source sequence into two groups, based on the result of the given filtering function.
public static (List<TSource> TruthyValues, List<TSource> FalsyValues) Bifurcate<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> fn);
TSource
The type of the elements of source
.
source
IEnumerable <TSource>
A sequence of values to determine if they are true or false.
fn
Func <TSource, bool>
A predicate function that asserts each element of the source sequence for a condition.
Tuple of (List <TSource>,List <TSource>)
A tuple containing a list of all values evaluated as true
, and a list containing a list of all values evaluated as false
.
The following code example demonstrates how to use Bifurcate(Func<TSource, bool> fn) to partition the sequence in "truthy" and "falsy" values, based on the fn
predicate.
var source = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var (TruthyValues, FalsyValues) = source.Bifurcate(x => x % 2 == 0);
//=> TruthyValues = { 2, 4, 6, 8, 10 }
//=> FalsyValues = { 1, 3, 5, 7, 9 }