Skip to content

Instantly share code, notes, and snippets.

@agross
Created June 22, 2010 11:26
Show Gist options
  • Save agross/448350 to your computer and use it in GitHub Desktop.
Save agross/448350 to your computer and use it in GitHub Desktop.
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