# Simple Immutable Stack in C# 
```csharp
public record SimpleImmutableStack<T> : IEnumerable<T> where T : class
{
    private record _Empty() : SimpleImmutableStack<T>(null, null)
    {
        public override bool IsEmpty => true;
        public override SimpleImmutableStack<T> Pop() => throw new InvalidOperationException("Stack is empty");
        public override T Peek() => throw new InvalidOperationException("Stack is empty");
    }
    public static readonly SimpleImmutableStack<T> Empty = new _Empty();
    private readonly T Head;
    private readonly SimpleImmutableStack<T> Tail;
    private SimpleImmutableStack(T head, SimpleImmutableStack<T> tail)
    {
        Head = head;
        Tail = tail;
    }
    public virtual bool IsEmpty => false;
    public SimpleImmutableStack<T> Push(T value) => new(value, this);
    public virtual SimpleImmutableStack<T> Pop() => Tail;
    public virtual T Peek() => Head;
    public IEnumerator<T> GetEnumerator()
    {
        IEnumerable<T> Inner()
        {
            var current = this;
            while (current.IsEmpty == false)
            {
                yield return current.Head;
                current = current.Tail;
            }
        }
        return Inner().GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
```