Skip to content
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

Consider Else overloads that return a Maybe<T> #9

Open
j2jensen opened this issue Aug 21, 2017 · 1 comment
Open

Consider Else overloads that return a Maybe<T> #9

j2jensen opened this issue Aug 21, 2017 · 1 comment

Comments

@j2jensen
Copy link
Owner

This could allow chaining fallbacks:

var value = GetValueFromCacheMaybe().Else(() => GetValueFromDatabaseMaybe()).Else(DefaultValue);
@j2jensen
Copy link
Owner Author

A brief proof of concept shows that this extension method doesn't seem to conflict with the other Else method. The compiler is still able to infer the return type when it's used.

        public static Maybe<T> Else<T>(this Maybe<T> src, Func<Maybe<T>> elseSelector)
        {
            return src.HasValue ? src : elseSelector();
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant