Skip to content

Instantly share code, notes, and snippets.

@dcomartin dcomartin/Either.cs

Created Jul 22, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.