-
Notifications
You must be signed in to change notification settings - Fork 310
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
ValueOr and AsMaybe for results #594
Comments
Hey @RorySan, There's a public T GetValueOrDefault(T defaultValue)
{
if (HasNoValue)
return defaultValue;
return _value;
} For the |
Thanks for your reply @bothzoli , although I think GetValueOrDefault wouldn't work in this case because I am not returning T but string. I'll get back to you with the detailed use case and we can decide if it might make sense to include it. I've been exploring functional programming for a while now and I use this library extensively. I'm not very experienced with contributions, but I'd be happy to help if that's ok. |
In the extension method you sent above, the generic type constraint makes This all however makes me wonder what you use the |
You can do a Maybe<MyValueObject> myMaybe = ...
myMaybe
.Map(x => x.Value) // Maybe<string>
.GetValueOrDefault(string.Empty) // string
|
I see @vkhorikov . I'll tinker a bit with my use case and let you know. Your solution seems right, although I think it made sense for me to have a custom method for brevity given I use it a lot on my UI. That does not justify adding it to the library tho. Regarding the AsMaybe for Result, shall I prepare a PR with the functionality and tests and send it your way? Seems small enough for a first timer 😅. Is there anything special I should take into account? Thanks! |
Yep, feel free to submit a PR please |
I've sent the PR. I'm not experienced at all in these matters, this is my first PR to an open source project. If I'm doing something wrong or not following best practices, please do not hesitate to point it out. Thanks. |
Adding PR reference #597. |
Hello, I wrote two simple extension methods that are helping me in my project, but I'm guessing there is probably a better alternative already built in that I am not using:
I found a way of using the existing Or to achieve this, but it is a bit more verbose. With this ValueOr i get to write things like
Email.ValueOr(string.Empty)
which is handy when displaying optional info on the UI. Am I missing a better way of doing this?The text was updated successfully, but these errors were encountered: