Either<TLeft, TRight>
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace System.Reactive
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal abstract class Either<[System.Runtime.CompilerServices.Nullable(2)] TLeft, [System.Runtime.CompilerServices.Nullable(2)] TRight>
{
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1,
1
})]
public sealed class Left : Either<TLeft, TRight>, IEquatable<Left>
{
public TLeft Value { get; }
public Left(TLeft value)
{
Value = value;
}
public override TResult Switch<[System.Runtime.CompilerServices.Nullable(2)] TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight)
{
return caseLeft(this.Value);
}
public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
{
caseLeft(Value);
}
public bool Equals([System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1,
1
})] Left other)
{
if (other == this)
return true;
if (other == null)
return false;
return EqualityComparer<TLeft>.Default.Equals(Value, other.Value);
}
[System.Runtime.CompilerServices.NullableContext(2)]
public override bool Equals(object obj)
{
return Equals(obj as Left);
}
public override int GetHashCode()
{
TLeft value = Value;
return value?.GetHashCode() ?? 0;
}
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "Left({0})", Value);
}
}
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1,
1
})]
public sealed class Right : Either<TLeft, TRight>, IEquatable<Right>
{
public TRight Value { get; }
public Right(TRight value)
{
Value = value;
}
public override TResult Switch<[System.Runtime.CompilerServices.Nullable(2)] TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight)
{
return caseRight(this.Value);
}
public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
{
caseRight(Value);
}
public bool Equals([System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1,
1
})] Right other)
{
if (other == this)
return true;
if (other == null)
return false;
return EqualityComparer<TRight>.Default.Equals(Value, other.Value);
}
[System.Runtime.CompilerServices.NullableContext(2)]
public override bool Equals(object obj)
{
return Equals(obj as Right);
}
public override int GetHashCode()
{
TRight value = Value;
return value?.GetHashCode() ?? 0;
}
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "Right({0})", Value);
}
}
private Either()
{
}
public static Either<TLeft, TRight> CreateLeft(TLeft value)
{
return new Left(value);
}
public static Either<TLeft, TRight> CreateRight(TRight value)
{
return new Right(value);
}
public abstract TResult Switch<[System.Runtime.CompilerServices.Nullable(2)] TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight);
public abstract void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight);
}
}