public IAsyncEnumerator <TSource> GetEnumerator() { AsyncIterator <TSource> asyncIterator = _state == AsyncIteratorState.New ? this : Clone(); asyncIterator._state = AsyncIteratorState.Allocated; return(asyncIterator); }
public static void Main() { Iterator.Test(); Async.Test(); AsyncIterator.Test(); LocalFunction.Test(); Lambda.Test(); Complex.Test(); }
private static async Task Main(string[] args) { await AsyncIterator.Demo(); Pattern.Demo(); DefaultInterfaceMember.Demo(); IndiceAndRange.Demo(); UsingStatementSample.Demo(); NullCoalescingAssignmentSample.Demo(); StaticLocalFunction.Demo(); ReadOnlyMember.Demo(); RefStruct.Demo(); StackAllocSample.Demo(); InterpolatedVerbatimString.Demo(); UnmanagedConstraintSample.Demo(); }
/// <summary> /// Projects each element of an async-enumerable sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by running the selector function for each element in the source sequence.</typeparam> /// <param name="source">A sequence of elements to invoke a transform function on.</param> /// <param name="selector">A transform function to apply to each source element.</param> /// <returns>An async-enumerable sequence whose elements are the result of invoking the transform function on each element of source.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IAsyncEnumerable <TResult> Select <TSource, TResult>(this IAsyncEnumerable <TSource> source, Func <TSource, TResult> selector) { if (source == null) { throw Error.ArgumentNull(nameof(source)); } if (selector == null) { throw Error.ArgumentNull(nameof(selector)); } return(source switch { AsyncIterator <TSource> iterator => iterator.Select(selector), IList <TSource> list => new SelectIListIterator <TSource, TResult>(list, selector), _ => new SelectEnumerableAsyncIterator <TSource, TResult>(source, selector), });