Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created October 13, 2011 02:37
Show Gist options
  • Save shiftkey/1283196 to your computer and use it in GitHub Desktop.
Save shiftkey/1283196 to your computer and use it in GitHub Desktop.
Experiment with alternative syntax to ?? and ? :
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