-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: AsMaybeAsync #528
Comments
Yes, looks good. Feel free to submit a PR please. |
perhaps include a implicit operator as well? i was working on a simular solution/problem. public static async Task<Maybe<T>> ToMaybeAsync<T, TE>(this Task<Result<T, TE>> task) where T : class
{
var result = await task.ConfigureAwait(false);
return result.IsSuccess ? Maybe<T>.From(result.Value) : Maybe<T>.None;
} But i guess the implicit converter would even be better. public static class MaybeExtensions
{
// Implicit conversion operator from Result<T, TE> to Maybe<T>
public static implicit operator Maybe<T>(Result<T, TE> result)
{
return result.IsSuccess ? Maybe<T>.From(result.Value) : Maybe<T>.None;
}
} I think i cannot add this directly in my code, can I? |
The lack of the implicit conversion is intentional. Check out this article: https://khorikov.org/posts/2021-11-08-converting-result-to-maybe/ |
Hello!
Any chance
AsMaybeAsync
could be added, just as we haveToResultAsync
?It would allow for less clutter when combined with EF.
Current:
Maybe<Entity> maybeEntity = (await dbContext.Entity.FirstOrDefaultAsync(x => x.Id == EntityId)).AsMaybe();
With AsMaybeAsync:
Maybe<Entity> maybeEntity = await dbContext.Entity.FirstOrDefaultAsync(x => x.Id == EntityId).AsMaybeAsync();
The text was updated successfully, but these errors were encountered: