export function ok(r: T) { return new Ok(r); } export function err(e: { new (string): E }) { return new Err(e); } export default abstract class Result { abstract expect(msg: string): T; abstract unwrap(): T; } class Ok extends Result { constructor(private r: T) { super(); } expect(msg: string): T { return this.r; } unwrap() { return this.r; } } class Err extends Result { constructor(private e: { new (string): E }) { super(); } expect(msg: string): R { throw new this.e(msg); } unwrap(): R { throw new this.e("Could not unwrap. Encountered error."); } }