/** 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));
        }
Beispiel #2
0
        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!"
               );
 }
Beispiel #4
0
 public bool Equals(Partitioned <A> other)
 {
     return(trues.SequenceEqual(other.trues) && falses.SequenceEqual(other.falses));
 }