Created
June 22, 2010 11:26
-
-
Save agross/448350 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var maybeNick = NicknamesToEmail | |
.Where(x => x.Nickname == fullNameOrEmail) | |
.Select(x => x.Email) | |
.ToMaybe(); | |
var maybeName = FullNamesToEmail | |
.Where(x => x.FullName == fullNameOrEmail) | |
.Select(x => x.Email) | |
.ToMaybe(); | |
var maybePrefs = from name in new[] { maybeNick, maybeName} | |
from prefs in EmailToPreferences | |
where !name.IsNone | |
where prefs.Email == name.Some | |
select prefs.EmailPreferences; | |
return maybePrefs.ToMaybe(); | |
internal static class EnumerableExtensions | |
{ | |
public static Maybe<T> ToMaybe<T>(this IEnumerable<T> instance) | |
{ | |
if (!instance.Any()) | |
return Maybe<T>.None; | |
return Maybe.From(instance.First()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment