AsyncLinqIterator<TResult>
Namespace: SnowBank.Linq.Async.Iterators · class
Implements: IAsyncLinqQuery<TResult>, IAsyncQuery<TResult>, IAsyncEnumerable<TResult>, IAsyncEnumerator<TResult>, IAsyncDisposable
Base class for all async iterators
Properties
Cancellation
CancellationToken Cancellation { get; }
Cancellation token that should be used by all async operations performed in the context of this query
This token is controlled by the source (usually a transaction or other transient scope)
Current
TResult Current { get; }
Methods
AllAsync
Task<bool> AllAsync(Func<TResult, bool> predicate)
Task<bool> AllAsync(Func<TResult, 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<TResult, bool> predicate)
Task<bool> AnyAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
CountAsync
Task<int> CountAsync()
Returns the number of elements returned by this query.
Task<int> CountAsync(Func<TResult, bool> predicate)
Returns the number of elements returned by this query that match the given predicate.
Task<int> CountAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
Returns the number of elements returned by this query that match the given predicate.
DisposeAsync
ValueTask DisposeAsync()
ExecuteAsync
Task ExecuteAsync(Action<TResult> handler)
Execute an action on the result of this async sequence
Task ExecuteAsync(Func<TResult, CancellationToken, Task> handler)
Task ExecuteAsync<TState>(TState state, Action<TState, TResult> handler)
Execute an action on the result of this async sequence
Task<TAggregate> ExecuteAsync<TAggregate>(TAggregate seed, Func<TAggregate, TResult, TAggregate> handler)
Execute an action on the result of this async sequence
Task ExecuteAsync<TState>(TState state, Func<TState, TResult, CancellationToken, Task> handler)
Task<TAggregate> ExecuteAsync<TState, TAggregate>(TState state, TAggregate seed, Func<TState, TAggregate, TResult, TAggregate> handler)
Execute an action on the result of this async sequence
FirstAsync
Task<TResult> FirstAsync()
Returns the first result of the query, or an exception if the query yields no result.
Task<TResult> FirstAsync(Func<TResult, bool> predicate)
Task<TResult> FirstAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
FirstOrDefaultAsync
Task<TResult> FirstOrDefaultAsync()
Returns the first result of the query, or the default for this type if the query yields no results.
Task<TResult> FirstOrDefaultAsync(TResult defaultValue)
Returns the first result of the query, or the default for this type if the query yields no results.
Task<TResult> FirstOrDefaultAsync(Func<TResult, bool> predicate)
Returns the first result of the query, or the default for this type if the query yields no results.
Task<TResult> FirstOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
Returns the first result of the query, or the default for this type if the query yields no results.
Task<TResult> FirstOrDefaultAsync(Func<TResult, bool> predicate, TResult defaultValue)
Task<TResult> FirstOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate, TResult defaultValue)
GetAsyncEnumerator
IAsyncEnumerator<TResult> GetAsyncEnumerator(AsyncIterationHint mode)
Gets an asynchronous enumerator over the sequence.
Returns: Enumerator for asynchronous enumeration over the sequence.
LastAsync
Task<TResult> LastAsync()
Returns the last result of the query, or an exception if the query yields no result.
Task<TResult> LastAsync(Func<TResult, bool> predicate)
Task<TResult> LastAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
LastOrDefaultAsync
Task<TResult> LastOrDefaultAsync()
Returns the last result of the query, or the default for this type if the query yields no results.
Task<TResult> LastOrDefaultAsync(TResult defaultValue)
Task<TResult> LastOrDefaultAsync(Func<TResult, bool> predicate)
Task<TResult> LastOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
Task<TResult> LastOrDefaultAsync(Func<TResult, bool> predicate, TResult defaultValue)
Task<TResult> LastOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate, TResult defaultValue)
MaxAsync
Task<TResult> MaxAsync(IComparer<TResult> comparer = null)
MinAsync
Task<TResult> MinAsync(IComparer<TResult> comparer = null)
MoveNextAsync
ValueTask<bool> MoveNextAsync()
Select
IAsyncLinqQuery<TNew> Select<TNew>(Func<TResult, 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<TResult, 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<TResult, CancellationToken, Task<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<TResult, int, CancellationToken, Task<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) => $" = ")
SelectMany
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<TResult, IEnumerable<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<TResult, CancellationToken, Task<IEnumerable<TNew>>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<TResult, IAsyncEnumerable<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TNew>(Func<TResult, IAsyncQuery<TNew>> selector)
IAsyncLinqQuery<TNew> SelectMany<TCollection, TNew>(Func<TResult, IEnumerable<TCollection>> collectionSelector, Func<TResult, TCollection, TNew> resultSelector)
IAsyncLinqQuery<TNew> SelectMany<TCollection, TNew>(Func<TResult, CancellationToken, Task<IEnumerable<TCollection>>> collectionSelector, Func<TResult, TCollection, TNew> resultSelector)
SingleAsync
Task<TResult> SingleAsync()
Returns the only result of the query, or an exception if it yields either zero, or more than one result.
Task<TResult> SingleAsync(Func<TResult, bool> predicate)
Task<TResult> SingleAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
SingleOrDefaultAsync
Task<TResult> SingleOrDefaultAsync()
Returns the last result of the query, or the default for this type if the query yields no results.
Task<TResult> SingleOrDefaultAsync(TResult defaultValue)
Task<TResult> SingleOrDefaultAsync(Func<TResult, bool> predicate)
Task<TResult> SingleOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate)
Task<TResult> SingleOrDefaultAsync(Func<TResult, bool> predicate, TResult defaultValue)
Task<TResult> SingleOrDefaultAsync(Func<TResult, CancellationToken, Task<bool>> predicate, TResult defaultValue)
Skip
IAsyncLinqQuery<TResult> Skip(int count)
SumAsync
Task<TResult> SumAsync()
Take
IAsyncLinqQuery<TResult> Take(int count)
IAsyncLinqQuery<TResult> Take(Range range)
TakeWhile
IAsyncLinqQuery<TResult> TakeWhile(Func<TResult, bool> condition)
ToArrayAsync
Task<TResult[]> ToArrayAsync()
Returns an array with all the elements of the range results
ToAsyncEnumerable
IAsyncEnumerable<TResult> 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, TResult>> ToDictionaryAsync<TKey>(Func<TResult, TKey> keySelector, IEqualityComparer<TKey> comparer = null)
Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TKey, TElement>(Func<TResult, TKey> keySelector, Func<TResult, TElement> elementSelector, IEqualityComparer<TKey> comparer = null)
Returns a dictionary with the decoded keys and values of the range results
ToHashSetAsync
Task<HashSet<TResult>> ToHashSetAsync(IEqualityComparer<TResult> comparer = null)
ToImmutableArrayAsync
Task<ImmutableArray<TResult>> ToImmutableArrayAsync()
ToListAsync
Task<List<TResult>> ToListAsync()
Returns a list of all the elements of the range results
Where
IAsyncLinqQuery<TResult> Where(Func<TResult, 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<TResult> Where(Func<TResult, int, 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<TResult> Where(Func<TResult, CancellationToken, Task<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<TResult> Where(Func<TResult, int, CancellationToken, Task<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)