public bool Equals(Either <TLeft, TRight> other) => isLeft == other.isLeft && (isLeft ? Equals(left, other.left) : Equals(right, other.right));
/// <summary> /// Maps the right/success value to another value. /// <para /> /// Will only be executed when the left/error condition is not set. /// </summary> /// <typeparam name="TR">Resulting type</typeparam> /// <param name="func">mapping function</param> public Either <TLeft, TR> Map <TR>(Func <TRight, TR> func) => Fold(Either.Left <TLeft, TR>, r => Either.Right <TLeft, TR>(func(r)));
/// <summary> /// Maps the right/success value to another value. /// <para /> /// Will only be executed when the left/error condition is not set. /// </summary> /// <typeparam name="TL">Resulting left/error type</typeparam> /// <typeparam name="TR">Resulting right/success type</typeparam> /// <param name="leftFunc">Delegate to map the left/error value</param> /// <param name="rightFunc">Delegate to map the right/success value</param> /// <remarks>Also called bimap in some implementations.</remarks> public Either <TL, TR> Map <TL, TR>(Func <TLeft, TL> leftFunc, Func <TRight, TR> rightFunc) => Fold(l => Either.Left <TL, TR>(leftFunc(l)), r => Either.Right <TL, TR>(rightFunc(r)));
public static Maybe <TRight> AsMaybe <TLeft, TRight>(this Either <TLeft, TRight> source) { return(source.Adjust( left => Nothing, right => Just(right))); }