Skip to content

Instantly share code, notes, and snippets.

@TimDumol
Created October 10, 2014 08:14
Show Gist options
  • Save TimDumol/684ba857e9b3ff1b68d7 to your computer and use it in GitHub Desktop.
Save TimDumol/684ba857e9b3ff1b68d7 to your computer and use it in GitHub Desktop.
Option<T>
class Option<T> {
private T val;
private bool hasVal;
public Option<T>() {
hasVal = false;
}
public Option<T>(T val) {
this.val = val;
hasVal = true;
}
public bool isSome() {
return hasVal;
}
public bool get() {
if (!hasVal) {
throw new EntityNotFoundException();
}
return val;
}
}
class MyObject {
public static Option<MyObject> findBy(int id) {
if (!found) {
return new Option();
}
return new Option(foundObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment