Created
October 13, 2011 02:37
-
-
Save shiftkey/1283196 to your computer and use it in GitHub Desktop.
Experiment with alternative syntax to ?? and ? :
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
public int Floor(int value) | |
{ | |
return value.Unless(v => v < 0, () => 0); | |
} | |
public static T Unless<T>(this T obj, Func<T, bool> term, Func<T> result) | |
{ | |
if (term(obj)) | |
return result(); | |
return obj; | |
} | |
// alternatively | |
public int Floor(int value) | |
{ | |
return value.Unless(that: v => v < 0, then: 0); | |
} | |
public static T Unless<T>(this T obj, Predicate<T> that, T then) | |
{ | |
if (that(obj)) | |
return then; | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment