Class AsyncEnumerableExtensions
Inherited Members
Namespace: Unity.Cloud.DataStreaming.Metadata
Assembly: Unity.Cloud.DataStreaming.Runtime.dll
Syntax
public static class AsyncEnumerableExtensions
Methods
GetFirstOrDefaultAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Gets the first element of the sequence or a default value if the sequence contains no elements.
Declaration
public static Task<T> GetFirstOrDefaultAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<T> | enumerable | The IAsyncEnumerable<T> to get the first element from. |
| CancellationToken | cancellationToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> | The first element of the sequence or a default value if the sequence contains no elements. |
Type Parameters
| Name | Description |
|---|---|
| T | Returned value type. |
ToDictionaryAsync<TSource, TKey, TElement>(IAsyncEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, CancellationToken)
Converts the IAsyncEnumerable<T> to a Dictionary<TKey, TValue>.
Declaration
public static Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> enumerable, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | enumerable | The IAsyncEnumerable<T> to convert. |
| Func<TSource, TKey> | keySelector | |
| Func<TSource, TElement> | elementSelector | |
| CancellationToken | cancellationToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<Dictionary<TKey, TElement>> | The converted result. Returns an empty dictionary if the enumerable has no more items to iterate. |
Type Parameters
| Name | Description |
|---|---|
| TSource | Type of each elements part of the enumerable. |
| TKey | Type of each key part of the returned dictionary. |
| TElement | Type of each element part of the returned dictionary. |
ToListAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Converts the IAsyncEnumerable<T> to a List<T>.
Declaration
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<T> | enumerable | The IAsyncEnumerable<T> to convert. |
| CancellationToken | cancellationToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<List<T>> | The converted result. Returns an empty list if the enumerable has no more items to iterate. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of each elements part of the enumerable. |