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:
public static Maybe<T> AsMaybe<T>(this Result<T> result) =>
result.IsSuccess ? result.Value : Maybe<T>.None;
public static string ValueOr<T>(this Maybe<T> maybe, string alternativeValue)
where T : SimpleValueObject<string> =>
maybe.HasValue ? maybe.Value : alternativeValue;
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?
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?