using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace Immutable { public class PureImmutableEnumeratorElement : IImmutableEnumeratorElement { private U element; private IImmutableEnumerator rest; private int hashCode; public PureImmutableEnumeratorElement(U element, IImmutableEnumerator rest) { this.element = element; this.rest = rest; this.hashCode = Equality.HashCode("PureImmutableEnumeratorElement", element, rest); } public static bool operator ==(PureImmutableEnumeratorElement a, PureImmutableEnumeratorElement b) => Equality.Operator(a, b); public static bool operator !=(PureImmutableEnumeratorElement a, PureImmutableEnumeratorElement b) => !(a == b); public override bool Equals(object other) => Equality.Untyped>( this, other, x => x as PureImmutableEnumeratorElement, x => x.hashCode, // Two immutable enumerators are equal if and only if // they have the same (immutable) state and use the same // generator lambda. x => x.element, x => x.rest); public bool Equals(IImmutableEnumeratorElement other) => Equality.Equatable>(this, other); public override int GetHashCode() => hashCode; public override string ToString() => "PureImmutableEnumeratorElement"; public void Dispose() { /* Nothing to do */ } public U First { get => element; } public IImmutableEnumerator Rest { get => rest; } public Option> MoveNext() => rest.MoveNext(); } }