Bifurcate
Splits values into two groups.
If an element in filter
is true
, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
- Use
IEnumerable.Where()
to separate values into two groups and assign them to the two passedout
arrays.
using System.Collections.Generic;
using System.Linq;
public static partial class _30s
{
public static void Bifurcate<T>(IEnumerable<T> items, IList<bool> filter, out T[] filteredTrue, out T[] filteredFalse)
{
filteredTrue = items.Where((val, i) => filter[i] == true).ToArray();
filteredFalse = items.Where((val, i) => filter[i] == false).ToArray();
}
}