feature: document handlers

This commit is contained in:
Gary Sharp
2022-12-03 14:32:05 +11:00
parent 96cccab958
commit 13e666d95a
26 changed files with 1027 additions and 120 deletions
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Disco
{
@@ -26,4 +28,61 @@ namespace Disco
}
}
public static class OneOf
{
public static OneOf<T> Create<T>(T instance)
=> OneOf<T>.Create(instance);
}
public struct OneOf<T> : IEnumerable<T>
{
private readonly T instance;
private OneOf(T instance)
{
this.instance = instance;
}
public static OneOf<T> Create(T instance)
=> new OneOf<T>(instance);
public IEnumerator<T> GetEnumerator()
=> new OneOfEnumerator(instance);
IEnumerator IEnumerable.GetEnumerator()
=> new OneOfEnumerator(instance);
private struct OneOfEnumerator : IEnumerator<T>
{
private readonly T instance;
private bool moved;
public OneOfEnumerator(T instance)
{
this.instance = instance;
moved = false;
}
public T Current => instance;
object IEnumerator.Current => instance;
public void Dispose() { }
public bool MoveNext()
{
if (!moved)
{
moved = true;
return true;
}
return false;
}
public void Reset()
{
moved = false;
}
}
}
}