IAsyncLinqQuery<T>
Namespace: SnowBank.Linq · interface
Implements: IAsyncQuery<T>
Provides optimized LINQ operations other the results of an asynchronous query
Methods
AllAsync
Task<bool> AllAsync(Func<T, bool> predicate)
Task<bool> AllAsync(Func<T, CancellationToken, Task<bool>> predicate)
AnyAsync
Task<bool> AnyAsync()
Returns true if the range query yields at least one element, or false if there was no result.
Task<bool> AnyAsync(Func<T, bool> predicate)
Task<bool> AnyAsync(Func<T, CancellationToken, Task<bool>> predicate)
CountAsync
Task<int> CountAsync()
Returns the number of elements returned by this query.
Task<int> CountAsync(Func<T, bool> predicate)
Returns the number of elements returned by this query that match the given predicate.
Task<int> CountAsync(Func<T, CancellationToken, Task<bool>> predicate)
Returns the number of elements returned by this query that match the given predicate.
FirstAsync
Task<T> FirstAsync()
Returns the first result of the query, or an exception if the query yields no result.
Task<T> FirstAsync(Func<T, bool> predicate)
Task<T> FirstAsync(Func<T, CancellationToken, Task<bool>> predicate)
FirstOrDefaultAsync
Task<T> FirstOrDefaultAsync()
Returns the first result of the query, or the default for this type if the query yields no results.
Task<T> FirstOrDefaultAsync(T defaultValue)
Returns the first result of the query, or the default for this type if the query yields no results.
Task<T> FirstOrDefaultAsync(Func<T, bool> predicate)
Task<T> FirstOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate)
Task<T> FirstOrDefaultAsync(Func<T, bool> predicate, T defaultValue)
Task<T> FirstOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate, T defaultValue)
LastAsync
Task<T> LastAsync()
Returns the last result of the query, or an exception if the query yields no result.
Task<T> LastAsync(Func<T, bool> predicate)
Task<T> LastAsync(Func<T, CancellationToken, Task<bool>> predicate)
LastOrDefaultAsync
Task<T> LastOrDefaultAsync()
Returns the last result of the query, or the default for this type if the query yields no results.
Task<T> LastOrDefaultAsync(T defaultValue)
Task<T> LastOrDefaultAsync(Func<T, bool> predicate)
Task<T> LastOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate)
Task<T> LastOrDefaultAsync(Func<T, bool> predicate, T defaultValue)
Task<T> LastOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate, T defaultValue)
MaxAsync
Task<T> MaxAsync(IComparer<T> comparer = null)
MinAsync
Task<T> MinAsync(IComparer<T> comparer = null)
Select
IAsyncLinqQuery<TNew> Select<TNew>(Func<T, TNew> selector)
Projects each element of the range results into a new form.
selector— Function that is invoked for each source element, and will return the corresponding transformed element.
Returns: New range query that outputs the sequence of transformed elements
query.Select((kv) => $" = ")
IAsyncLinqQuery<TNew> Select<TNew>(Func<T, int, TNew> selector)
Projects each element of the range results into a new form.
selector— Function that is invoked for each source element, and will return the corresponding transformed element.
Returns: New range query that outputs the sequence of transformed elements
query.Select((kv) => $" = ")
IAsyncLinqQuery<TNew> Select<TNew>(Func<T, CancellationToken, Task<TNew>> selector)
IAsyncLinqQuery<TNew> Select<TNew>(Func<T, int, CancellationToken, Task<TNew>> selector)
SelectMany
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<T, IEnumerable<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<T, CancellationToken, Task<IEnumerable<TNew>>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<T, IAsyncEnumerable<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<T, IAsyncQuery<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TCollection, TNew>(Func<T, IEnumerable<TCollection>> collectionSelector, Func<T, TCollection, TNew> resultSelector)
IAsyncLinqQuery<TNew> SelectMany<TCollection, TNew>(Func<T, CancellationToken, Task<IEnumerable<TCollection>>> collectionSelector, Func<T, TCollection, TNew> resultSelector)
SingleAsync
Task<T> SingleAsync()
Returns the only result of the query, or an exception if it yields either zero, or more than one result.
Task<T> SingleAsync(Func<T, bool> predicate)
Task<T> SingleAsync(Func<T, CancellationToken, Task<bool>> predicate)
SingleOrDefaultAsync
Task<T> SingleOrDefaultAsync()
Returns the last result of the query, or the default for this type if the query yields no results.
Task<T> SingleOrDefaultAsync(T defaultValue)
Task<T> SingleOrDefaultAsync(Func<T, bool> predicate)
Task<T> SingleOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate)
Task<T> SingleOrDefaultAsync(Func<T, bool> predicate, T defaultValue)
Task<T> SingleOrDefaultAsync(Func<T, CancellationToken, Task<bool>> predicate, T defaultValue)
Skip
IAsyncLinqQuery<T> Skip(int count)
SumAsync
Task<T> SumAsync()
Take
IAsyncLinqQuery<T> Take(int count)
IAsyncLinqQuery<T> Take(Range range)
TakeWhile
IAsyncLinqQuery<T> TakeWhile(Func<T, bool> condition)
ToArrayAsync
Task<T[]> ToArrayAsync()
Returns an array with all the elements of the range results
ToAsyncEnumerable
IAsyncEnumerable<T> ToAsyncEnumerable(AsyncIterationHint hint = 0)
Returns an IAsyncEnumerable view of this query
hint— Hint passed to the source provider.
Returns: Sequence that will asynchronously return the results of this query.
For best performance, the caller should take care to provide a hint that matches how this query will be consumed downstream.
If the hint does not match, performance may be degraded. For example, if the caller will consumer this query using await foreach or ToListAsync, but uses Iterator, the provider may fetch small pages initially, before ramping up. The opposite is also true if the caller uses All but consumes the query using AnyAsync() or FirstOrDefaultAsync, the provider may fetch large pages and waste most of it except the first few elements.
ToDictionaryAsync
Task<Dictionary<TKey, T>> ToDictionaryAsync<TKey>(Func<T, TKey> keySelector, IEqualityComparer<TKey> comparer = null)
Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TKey, TElement>(Func<T, TKey> keySelector, Func<T, TElement> elementSelector, IEqualityComparer<TKey> comparer = null)
Returns a dictionary with the decoded keys and values of the range results
ToHashSetAsync
Task<HashSet<T>> ToHashSetAsync(IEqualityComparer<T> comparer = null)
ToImmutableArrayAsync
Task<ImmutableArray<T>> ToImmutableArrayAsync()
ToListAsync
Task<List<T>> ToListAsync()
Returns a list of all the elements of the range results
Where
IAsyncLinqQuery<T> Where(Func<T, bool> predicate)
Filters the range results based on a predicate.
Caution: filtering occurs on the client side !
query.Where((kv) => kv.Key.StartsWith(prefix)) or query.Where((kv) => !kv.Value.IsNull)
IAsyncLinqQuery<T> Where(Func<T, int, bool> predicate)
IAsyncLinqQuery<T> Where(Func<T, CancellationToken, Task<bool>> predicate)
IAsyncLinqQuery<T> Where(Func<T, int, CancellationToken, Task<bool>> predicate)