Skip to content

Instantly share code, notes, and snippets.

@gxclarke
Created November 23, 2013 22:55
Show Gist options
  • Save gxclarke/7621080 to your computer and use it in GitHub Desktop.
Save gxclarke/7621080 to your computer and use it in GitHub Desktop.
Nullable Monad Pattern Example: SiteMapBase.GetActualCurrentNode().IfNotNull(x => x.Title)
public static TResult IfNotNull<T, TResult>(this T input, Func<T, TResult> action, TResult valueIfNull)
where T : class
{
if (input != null) return action(input);
else return valueIfNull;
}
public static TResult IfNotNull<T, TResult>(this T input, Func<T, TResult> action)
where T : class
where TResult : class
{
return input.IfNotNull(action, null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment