vkhorikov / CSharpFunctionalExtensions

Functional extensions for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add IError<string> to the Result struct

nicksoethof opened this issue · comments

Why is the Result.cs struct not decorated with the IError<string> interface? The Result<T> struct does have the IError<string> interface decorated.

Both the Result and the Result<T> structs have the string Error property.

We could just add the interface without any issue, like below:

[Serializable]
public readonly partial struct Result : IResult, ISerializable, IError<string>
{

Nice question, I was also guessing. Several times I had to write generic result handling (where actual type may be Result, Result<>, Result<,> or UnitResult<>) and I faced the same issue. Eventually I added a special case for Result, while all other results were covered with IResult and IError cases

Yeah, that was an oversight on my part. Feel free to submit a PR with a fix.

Feel free to review the PR.
Result<T> didn't need this interface as it already implements it via the following:

  • Result<T> : IResult<T>
  • IResult<out T> : IResult<T, string>
  • IResult<out T, out E> : IValue<T>, IUnitResult<E> (<E> is string at this point)
  • IUnitResult<out E> : IResult, IError<E> (<E> is string at this point)