// type T0 = Exclude; // type T2 = Exclude void), Function>; // type Omit = Pick>; // type SubPartial = Omit & Partial>; export class Optional { static readonly EMPTY = new Optional(); constructor(private value?: T) { } public static ofNullable(value: T): Optional { return value == null ? Optional.empty() : Optional.of(value); } public static of(value: T): Optional { return new Optional(value); } public orElse(other: T): T { const val = this.isPresent() ? this.value : other; // return (this.value != null && this.value != undefined) ? this.value : other; return val as T; } public isPresent(): boolean { return (this.value != null && this.value != undefined); } // public ifPresent(Consumer consumer) { // if (value != null) // consumer.accept(value); // } public static empty(): Optional { return Optional.EMPTY as Optional; } // public static default(value: any, def: T): T { // return (value != null && value != undefined) ? value : def; // } }