Skip to content

Instantly share code, notes, and snippets.

@dchenbecker
Created May 27, 2010 22:32
Show Gist options
  • Save dchenbecker/416450 to your computer and use it in GitHub Desktop.
Save dchenbecker/416450 to your computer and use it in GitHub Desktop.
class DefaultNullable<A,B> {
public delegate B MapFunc(A input);
private A underlying;
public DefaultNullable(A input) {
this.underlying = input;
}
public static implicit operator DefaultNullable<A,B>(A input) {
return new DefaultNullable<A,B>(input);
}
public B getDefault(MapFunc f, B defaultVal) {
if (underlying == null) {
return f(underlying);
} else {
return defaultVal;
}
}
}
@dchenbecker
Copy link
Author

Doh. Didn't remember that "in" is a keyword :P

@dchenbecker
Copy link
Author

This is what I get for doing my coding in gist instead of actually trying to use an IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment