예제 #1
0
        public static IPromiseEnumerator <IPromiseGrouping <TKey, TValue> > GroupBy <T, TKey, TValue>(
            IPromiseEnumerator <T> items,
            Func <T, int, IPromise <TKey> > key,
            Func <T, int, IPromise <TValue> > value,
            IEqualityComparer <TKey> comparer)
        {
            var tuples = SelectEnumerator.Create(items, (item, index) => key(item, index).Then(k => value(item, index).Then(v => Tuple.Create(k, v))));
            var keys   = DistinctEnumerator.Create(SelectEnumerator.Create(tuples, x => x.Item1));

            return(SelectEnumerator.Create(keys, k => (IPromiseGrouping <TKey, TValue>)(new PromiseGrouping <T, TKey, TValue>(k, tuples, comparer))));
        }
예제 #2
0
        public static IPromise <IPromiseEnumerator <Result> > GroupJoin <Inner, Outer, Key, Result>(
            IPromiseEnumerator <Inner> inner, IPromiseEnumerator <Outer> outer,
            Func <Inner, int, IPromise <Key> > innerKey, Func <Outer, int, IPromise <Key> > outerKey,
            Func <Outer, IPromiseEnumerable <Inner>, IPromise <Result> > result,
            IEqualityComparer <Key> comparer)
        {
            var innerKeys = SelectEnumerator.Create(inner, (x, i) => innerKey(x, i).Then(v => Tuple.Create(v, x)));

            return(inner.Factory.Value(SelectEnumerator.Create(outer, (x, i) => outerKey(x, i).Then(
                                                                   k => result(x, new PromiseEnumerable <Inner>(
                                                                                   inner.Factory.Value(SelectEnumerator.Create(WhereEnumerator.Create(innerKeys, y => comparer.Equals(y.Item1, k)), y => y.Item2))
                                                                                   ))))));
        }
예제 #3
0
 public static IPromise <IPromiseEnumerator <Value> > OrderBy <Key, Value>(IPromiseEnumerator <Value> items, Func <Value, int, IPromise <Key> > key, IComparer <Key> comparer)
 {
     return(CountAlgorithm.Count(items).Then(count =>
                                             OrderByInternal(items.Factory, SelectEnumerator.Create(items, (x, i) => key(x, i).Then(v => Tuple.Create(v, x))), count, comparer)
                                             .Then(i => SelectEnumerator.Create(i, x => x.Item2))));
 }
예제 #4
0
 public PromiseGrouping(TKey key, IPromiseEnumerator <Tuple <TKey, TValue> > items, IEqualityComparer <TKey> comparer)
     : base(items.Factory.Value(SelectEnumerator.Create(WhereEnumerator.Create(items, item => comparer.Equals(key, item.Item1)), item => item.Item2)))
 {
     this.Key = key;
 }