new-infofer-scraper/scraper/src/Utils/DeconstructIEnumerable.cs
Dan Cojocaru 7b13d09514
A whole C# rewrite
In one commit.
Yes, you're seeing it right.
Yes, I don't know what I was thinking.
2022-08-03 00:38:53 +03:00

18 lines
612 B
C#

using System.Collections.Generic;
using System.Diagnostics;
namespace InfoferScraper {
public static partial class Utils {
[DebuggerStepThrough]
public static void Deconstruct<T>(this IEnumerable<T> enumerable, out T? first, out IEnumerable<T> rest) {
var enumerator = enumerable.GetEnumerator();
first = enumerator.MoveNext() ? enumerator.Current : default;
rest = enumerator.AsEnumerable();
}
[DebuggerStepThrough]
private static IEnumerable<T> AsEnumerable<T>(this IEnumerator<T> enumerator) {
while (enumerator.MoveNext()) yield return enumerator.Current;
}
}
}