export class Optional { private object?: T; private constructor(object?: T) { this.object = object; } static ofNullable(object?: T): Optional { return new Optional(object); } isEmpty() { return this.object == null; } isPresent() { return this.object != null; } orElse(other: T): T { if(this.object != null) { return this.object; } return other; } get(): T { if(this.object != null) { return this.object; } throw new Error("No value present in Optional."); } }