using System; namespace RebootKit.Engine.Foundation { public readonly struct Either { public TLeft Left { get; } public TRight Right { get; } public bool IsRight { get; } public bool IsLeft => !IsRight; Either(TLeft left, TRight right, bool isRight) { Left = left; Right = right; IsRight = isRight; } public void Match(Action leftAction, Action rightAction) { if (IsRight) { rightAction(Right); } else { leftAction(Left); } } public static Either FromLeft(TLeft value) { return new Either(value, default, false); } public static Either FromRight(TRight value) { return new Either(default, value, true); } public override string ToString() { return IsRight ? $"Right({Right})" : $"Left({Left})"; } } }