diff --git a/src/util.ts b/src/util.ts index 18a427f..0c2f0a3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,7 @@ -import type {Ok, Err, Result} from "."; +import {ResultImpl, type Ok, type Err, type Result} from "./result"; +import {OptionImpl, type Option} from "./option"; +import {AsyncResult} from "./async_result"; +import {AsyncOption} from "./async_option"; export type InferOk = T extends Ok ? O : never; @@ -15,3 +18,19 @@ export type ExtractErr = T extends Err : T extends Result ? E : never; + +export function isResult(value: unknown): value is Result { + return value instanceof ResultImpl; +} + +export function isAsyncResult(value: unknown): value is AsyncResult { + return value instanceof AsyncResult; +} + +export function isOption(value: unknown): value is Option { + return value instanceof OptionImpl; +} + +export function isAsyncOption(value: unknown): value is AsyncOption { + return value instanceof AsyncOption; +}