/** Partitions enumerable into two lists using a predicate: (all false elements, all true elements) **/ public static Partitioned <A> partition <A>(this IEnumerable <A> enumerable, Fn <A, bool> predicate) { var trues = new List <A>(); var falses = new List <A>(); foreach (var a in enumerable) { (predicate(a) ? trues : falses).Add(a); } return(Partitioned.a(trues, falses)); }
public static Partitioned <A> partition <A>(this IEnumerable <A> enumerable, Fn <A, bool> predicate) { var trues = ImmutableList.CreateBuilder <A>(); var falses = ImmutableList.CreateBuilder <A>(); foreach (var a in enumerable) { (predicate(a) ? trues : falses).Add(a); } return(Partitioned.a(trues.ToImmutable(), falses.ToImmutable())); }
public bool Equals(Partitioned <A> other) { throw new InvalidOperationException( "Can't compare two partitioned datasets, because their lists are mutable!" ); }
public bool Equals(Partitioned <A> other) { return(trues.SequenceEqual(other.trues) && falses.SequenceEqual(other.falses)); }