Skip to content

Commit

Permalink
Rename new Either.Upcast method to From
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertie committed Apr 5, 2020
1 parent ac3a600 commit d2c9c6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Core/Loyc.Interfaces/Concrete/Either.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ private Either(bool hasLeft, L left, R right)
/// <remarks>
/// Sadly, automatically upcasting value types to reference types doesn't seem possible.
/// </remarks>
public static Either<L, R> Upcast<L2, R2>(Either<L2,R2> x)
public static Either<L, R> From<L2, R2>(Either<L2,R2> x)
where L2 : L
where R2 : R
=> new Either<L, R>(x._hasLeft, x._left, x._right);

/// <summary>Converts an Either to another with different types.</summary>
public Either<L2, R2> Select<L2, R2>(Func<L, L2> selectL, Func<R, R2> selectR)
=> _hasLeft ? new Either<L2, R2>(selectL(_left)) : selectR(_right);
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Tests/Essentials/Either.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void CastTest()
{
Either<string, ArgumentException> s = "Hi";
Either<string, ArgumentException> e = new ArgumentException();
var s2 = Either<object, Exception>.Upcast(s);
var e2 = Either<object, Exception>.Upcast(e);
var s2 = Either<object, Exception>.From(s);
var e2 = Either<object, Exception>.From(e);
Assert.AreEqual("Hi", s2.Value);
Assert.IsTrue(e2.Value is ArgumentException);

Expand Down

0 comments on commit d2c9c6d

Please sign in to comment.