示例#1
0
        /** 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));
        }
示例#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()));
        }
示例#3
0
 public bool Equals(Partitioned <A> other)
 {
     throw new InvalidOperationException(
               "Can't compare two partitioned datasets, because their lists are mutable!"
               );
 }
示例#4
0
 public bool Equals(Partitioned <A> other)
 {
     return(trues.SequenceEqual(other.trues) && falses.SequenceEqual(other.falses));
 }