Beispiel #1
0
        public static async Tasks.Task <T> First <T>(this IAsyncEnumerator <T> me)
        {
            T result;

            if (me.NotNull())
            {
                result = await me.MoveNext() ? me.Current : default(T);

                (me as IDisposable)?.Dispose();
            }
            else
            {
                result = default(T);
            }
            return(result);
        }
Beispiel #2
0
        public static Tasks.Task <T[]> ToArray <T>(this IAsyncEnumerator <T> me)
        {
            async Tasks.Task <T[]> toArray(int count)
            {
                T[] result;
                if (await me.MoveNext())
                {
                    var head = me.Current;
                    result = await toArray(count + 1);

                    result[count] = head;
                }
                else
                {
                    result = new T[count];
                }
                return(result);
            }

            return(me.NotNull() ? toArray(0) : null);
        }
Beispiel #3
0
 public static async Tasks.Task <T> Next <T>(this IAsyncEnumerator <T> me, T @default = default(T))
 {
     return(me.NotNull() && await me.MoveNext() ? me.Current : @default);
 }