-
Notifications
You must be signed in to change notification settings - Fork 2
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
New "Chain" operator for Option #31
Comments
Implementation idea: public static Option<TResult> Chain<TResult>(this Option<TResult> option, Option<TResult> other)
=> option.Match(some => some, none: other);
public static Option<TResult> Chain<TResult>(this Option<TResult> option, Func<Option<TResult>> other)
=> option.Match(some => some, none: other); |
I would not use We already have the method T? GetValueOrDefault();
T GetValueOrDefault(Func<T> defaultValue);
T GetValueOrDefault(T defaultValue); so I thought about extending it like: Option<T> GetValueOrDefault(Func<Option<T>> defaultValue);
Option<T> GetValueOrDefault(Option<T> defaultValue); but I don't think that's the better solution because the method name suggest getting the boxed value Another thing I would like to point out is that the var result = option1
.Concat(option2)
.Concat(option3)
.FirstOrDefault(fallbackValue) The Option<DateTime> result = Option.None<DateTime>().Concat(Option.None<DateTime>()).FirstOrDefault().ToOption(); // does not compile
Option<DateTime> result = Option.None<DateTime>().Concat(Option.None<DateTime>()).FirstOrDefault(); // is 99% a bug
Option<DateTime> result = Option.None<DateTime>().Concat(Option.None<DateTime>()).Cast<DateTime?>().FirstOrDefault().ToOption(); // works but is not intuitive |
I am looking for an operator for the following use case:
I have the following idea, the "Chain" operator:
It is somewhat inverse to Bind, in the sense that it does something in case the option is none, instead of in the case the option is some.
The text was updated successfully, but these errors were encountered: