public static IPromise <IPromiseEnumerator <T> > Intersect <T>(IPromiseEnumerator <T> left, IPromiseEnumerator <T> right, IEqualityComparer <T> comparer) { return(CountAlgorithm.Count(left).Then(leftCount => CountAlgorithm.Count(right).Then(rightCount => { if (leftCount < rightCount) { return Tuple.Create(left, right); } return Tuple.Create(right, left); })).Then(result => { var x = result.Item1; var y = result.Item2; return ToSetAlgorithm.ToSet(x, comparer).Then(lookup => WhereEnumerator.Create(y, q => lookup.Contains(q, comparer))); })); }
public IPromise <IPromiseEnumerator <T> > MoveNext() { return(_items.MoveNext().Then(result => { if (result == null) { return this.Factory.StartNew((IPromiseEnumerator <T>)null); } return _predicate(result.Current, _index).Then(take => { IPromiseEnumerator <T> ret = new WhereEnumerator <T>(_index + 1, result, _predicate); if (take) { return this.Factory.StartNew(ret); } return ret.MoveNext(); }); })); }
public static IPromise <T> Last <T>(IPromiseEnumerator <T> items, Func <T, bool> predicate) { return(Last(WhereEnumerator.Create(items, predicate))); }
public static IPromise <T> Single <T>(IPromiseEnumerator <T> items, Func <T, IPromise <bool> > predicate) { return(Single(WhereEnumerator.Create(items, predicate))); }
public static IPromise <T> First <T>(IPromiseEnumerator <T> items, Func <T, int, IPromise <bool> > predicate) { return(First(WhereEnumerator.Create(items, predicate))); }
public static IPromise <bool> Empty <T>(IPromiseEnumerator <T> items, Func <T, bool> predicate) { return(Empty(WhereEnumerator.Create(items, predicate))); }
public static IPromise <IPromiseEnumerator <T> > Difference <T>(IPromiseEnumerator <T> left, IPromiseEnumerator <T> right, IEqualityComparer <T> comparer) { return(ToSetAlgorithm.ToSet(right, comparer).Then(lookup => WhereEnumerator.Create(left, q => !lookup.Contains(q, comparer)))); }
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; }
public static IPromise <T> LastOrDefault <T>(IPromiseEnumerator <T> items, Func <T, int, IPromise <bool> > predicate) { return(LastOrDefault(WhereEnumerator.Create(items, predicate))); }
public static IPromise <T> LastOrDefault <T>(IPromiseEnumerator <T> items, Func <T, bool> predicate, T defaultValue) { return(LastOrDefault(WhereEnumerator.Create(items, predicate), defaultValue)); }
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)) )))))); }
public static IPromise <T> SingleOrDefault <T>(IPromiseEnumerator <T> items, Func <T, bool> predicate) { return(SingleOrDefault(WhereEnumerator.Create(items, predicate))); }
public static IPromise <T> SingleOrDefault <T>(IPromiseEnumerator <T> items, Func <T, int, IPromise <bool> > predicate, T defaultValue) { return(SingleOrDefault(WhereEnumerator.Create(items, predicate), defaultValue)); }