Skip to content

Commit

Permalink
result option method level type param constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Aug 30, 2024
1 parent 1b7caef commit e9ad934
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Danom/ResultOption/ResultOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,37 @@ public static Task<ResultOption<T, ResultErrors>> ErrorAsync(ResultErrors errors
public static Task<ResultOption<T, ResultErrors>> ErrorAsync(string message) =>
Task.FromResult(Error(message));
}

/// <summary>
/// Static methods for creating <see cref="ResultOption{T, ResultErrors}"/> instances with
/// <see cref="ResultErrors"/> as the error type.
/// </summary>
public static class ResultOption
{
/// <summary>
/// Creates a new <see cref="ResultOption{T, ResultErrors}"/> instance with the
/// specified value.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>/
public static ResultOption<T, ResultErrors> Ok<T>(T value) =>
ResultOption<T, ResultErrors>.Ok(value);

/// <summary>
/// Creates a new <see cref="ResultOption{T, ResultErrors}"/> instance with the
/// value of the awaited Task.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static Task<ResultOption<T, ResultErrors>> OkAsync<T>(T value) =>
ResultOption<T, ResultErrors>.OkAsync(value);

/// <summary>
/// Creates a new <see cref="ResultOption{T, ResultErrors}"/> instance with the
/// value of the awaited Task.
/// </summary>
/// <param name="valueTask"></param>
/// <returns></returns>
public static Task<ResultOption<T, ResultErrors>> OkAsync<T>(Task<T> valueTask) =>
ResultOption<T, ResultErrors>.OkAsync(valueTask);
}

0 comments on commit e9ad934

Please sign in to comment.