Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created July 22, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/0a0291d665c5d954a515bd2a2d3b4cd2 to your computer and use it in GitHub Desktop.
Save dcomartin/0a0291d665c5d954a515bd2a2d3b4cd2 to your computer and use it in GitHub Desktop.
public class Either<TLeft, TRight>
{
private readonly TLeft _left;
private readonly TRight _right;
private readonly bool _isLeft;
public Either(TLeft left)
{
_left = left;
_isLeft = true;
}
public Either(TRight right)
{
_right = right;
_isLeft = false;
}
public T Match<T>(Func<TLeft, T> left, Func<TRight, T> right)
{
return _isLeft ? left(_left) : right(_right);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment