Just tried this and seems to not allocate in Unity. Something more generic like IReadOnlyCollection can't be used as it allocates. ``` public static RefLinqEnumerable<T, HashSetEnumerator<T>> ToRefLinq<T>(this HashSet<T> c) => new(new(c)); public struct HashSetEnumerator<T> : IRefEnumerable<T> { private T curr; private HashSet<T>.Enumerator ie; public HashSetEnumerator(HashSet<T> list) { ie = list.GetEnumerator(); curr = default; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { bool end = ie.MoveNext(); curr = ie.Current; if(!end) ie.Dispose(); return end; } public T Current => curr; } ``` No idea if that Dispose is correct.
Activity
WhiteBlackGoose commentedon Jan 16, 2023
Nice! Would you mind making a PR or at least a patch?
[-]Add more types (HashSet etc)[/-][+]Add more types (Dictionary etc)[/+]