Skip to content

Commit

Permalink
simplify with Implicit casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeApophis committed Jun 3, 2024
1 parent fa7f3cf commit d83a4fd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Funcky/DownCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ private static Option<TResult> OptionDownCast<TItem>(TItem item)

private static Result<TResult> ResultDownCast<TValidResult>(TValidResult result)
where TValidResult : class
=> result as TResult is { } validResult
? Result.Ok(validResult)
: Result<TResult>.Error(new InvalidCastException());
=> result as TResult
?? Result<TResult>.Error(new InvalidCastException());

private static Func<TRight, Either<TLeft, TResult>> EitherDownCast<TLeft, TRight>(Func<TLeft> failedCast)
where TRight : class
where TLeft : notnull
=> right
=> right as TResult is { } result
? Either<TLeft, TResult>.Right(result)
: Either<TLeft, TResult>.Left(failedCast());
=> right as TResult
?? Either<TLeft, TResult>.Left(failedCast());
}

0 comments on commit d83a4fd

Please sign in to comment.