Created
June 9, 2014 11:02
-
-
Save amogram/e744fd7fd736e29e83cc to your computer and use it in GitHub Desktop.
Chained null checks- as explained in http://www.codeproject.com/Articles/109026/Chained-null-checks-and-the-Maybe-monad
This file contains 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
public static TResult With<TInput, TResult>(this TInput o, | |
Func<TInput, TResult> evaluator) | |
where TResult : class | |
where TInput : class | |
{ | |
if (o == null) return null; | |
return evaluator(o); | |
} | |
public static TResult Return<TInput, TResult>(this TInput o, | |
Func<TInput, TResult> evaluator, | |
TResult failureValue) where TInput : class | |
{ | |
if (o == null) return failureValue; | |
return evaluator(o); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment