public override FdbAsyncIterator <TResult> Where(Func <TResult, CancellationToken, Task <bool> > asyncPredicate) { if (asyncPredicate == null) { throw new ArgumentNullException("asyncPredicate"); } // note: the only possible optimization here is if TSource == TResult, then we can combine both predicates // remember: limit/offset are applied AFTER the filtering, so can only combine if they are null if (m_limit == null && (m_offset == null || m_offset.Value == 0) && typeof(TSource) == typeof(TResult)) //BUGBUG: type comparison maybe should check derived classes also ? { var asyncFilter = new AsyncFilterExpression <TSource>((Func <TSource, CancellationToken, Task <bool> >)(Delegate) asyncPredicate); if (m_filter != null) { asyncFilter = m_filter.AndAlso(asyncFilter); } //BUGBUG: if the query already has a select, it should be evaluated BEFORE the new filter, // but currently FdbWhereSelectAsyncIterator<> filters before transformations ! return(new FdbWhereSelectAsyncIterator <TSource, TResult>( m_source, asyncFilter, m_transform, m_limit, m_offset )); } // no easy optimization... return(base.Where(asyncPredicate)); }
public FdbWhereAsyncIterator([NotNull] IFdbAsyncEnumerable <TSource> source, AsyncFilterExpression <TSource> filter) : base(source) { Contract.Requires(filter != null, "there can be only one kind of filter specified"); m_filter = filter; }
public FdbWhereSelectAsyncIterator( [NotNull] IFdbAsyncEnumerable <TSource> source, AsyncFilterExpression <TSource> filter, AsyncTransformExpression <TSource, TResult> transform, int?limit, int?offset ) : base(source) { Contract.Requires(transform != null); // must do at least something Contract.Requires((limit ?? 0) >= 0 && (offset ?? 0) >= 0); // bounds cannot be negative m_filter = filter; m_transform = transform; m_limit = limit; m_offset = offset; }
public static AsyncFilterExpression <TSource> OrElse([NotNull] AsyncFilterExpression <TSource> left, [NotNull] AsyncFilterExpression <TSource> right) { if (left == null) { throw new ArgumentNullException("left"); } if (right == null) { throw new ArgumentNullException("right"); } // combine two expressions into a logical OR expression. // Note: if the first expression returns true, the second one will NOT be evaluated if (left.m_filter != null) { // we are async var f = left.m_filter; if (right.m_filter != null) { // so is the next one var g = right.m_filter; return(new AsyncFilterExpression <TSource>((x) => f(x) || g(x))); } else { // next one is async var g = right.m_asyncFilter; return(new AsyncFilterExpression <TSource>((x, ct) => f(x) ? TaskHelpers.TrueTask : g(x, ct))); } } else { // we are async var f = left.m_asyncFilter; if (right.m_asyncFilter != null) { // so is the next one var g = left.m_asyncFilter; return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) || (await g(x, ct).ConfigureAwait(false)))); } else { var g = left.m_filter; return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) || g(x))); } } }
public override FdbAsyncIterator <TResult> Where(Func <TResult, bool> predicate) { if (predicate == null) { throw new ArgumentNullException("predicate"); } // note: the only possible optimization here is if TSource == TResult, then we can combine both predicates // remember: limit/offset are applied AFTER the filtering, so can only combine if they are null // also, since transform is done after filtering, we can only optimize if transform is null (not allowed!) or the identity function if (m_limit == null && (m_offset == null || m_offset.Value == 0) && typeof(TSource) == typeof(TResult) && //BUGBUG: type comparison maybe should check derived classes also ? m_transform.IsIdentity()) { var filter = new AsyncFilterExpression <TSource>((Func <TSource, bool>)(Delegate) predicate); if (m_filter != null) { filter = m_filter.AndAlso(filter); } //BUGBUG: if the query already has a select, it should be evaluated BEFORE the new filter, // but currently FdbWhereSelectAsyncIterator<> filters before transformations ! return(new FdbWhereSelectAsyncIterator <TSource, TResult>( m_source, filter, m_transform, m_limit, m_offset )); } // no easy optimization... return(base.Where(predicate)); }
internal static FdbWhereAsyncIterator <TResult> Filter <TResult>( [NotNull] IFdbAsyncEnumerable <TResult> source, [NotNull] AsyncFilterExpression <TResult> filter) { return(new FdbWhereAsyncIterator <TResult>(source, filter)); }
public AsyncFilterExpression <TSource> AndAlso([NotNull] AsyncFilterExpression <TSource> expr) { return(AndAlso(this, expr)); }
public AsyncFilterExpression <TSource> OrElse([NotNull] AsyncFilterExpression <TSource> expr) { return(OrElse(this, expr)); }