import { Err, Result } from "../result"; import { Type } from "../type"; type Guard = (val: any) => val is T export class Is extends Type { readonly name: string readonly isT: Guard constructor(name: string, guard: Guard) { super() this.name = name this.isT = guard } check(val: any): Result { if(this.isT(val)) return val; return new Err(`${val} is not a ${this.name} (guard failed)`) } } export function is(name: string, guard: Guard) { return new Is(name, guard) }