Created
July 22, 2020 22:59
-
-
Save dcomartin/0a0291d665c5d954a515bd2a2d3b4cd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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