-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
19 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
import type {Result} from "./result" | ||
import {PromiseResult} from "./promise_result" | ||
import type {Err, InferErr, InferOk, Ok} from "./internal" | ||
import type {InferErr, InferOk} from "./internal" | ||
|
||
export function fn<A extends any[], R extends Result<any, any>>( | ||
f: (...args: A) => R, | ||
): (...args: A) => Result<InferOk<R>, InferErr<R>> { | ||
return f | ||
} | ||
|
||
export function asyncFn<A extends any[], T>( | ||
f: (...args: A) => Promise<Ok<T>>, | ||
): (...args: A) => PromiseResult<T, never> | ||
export function asyncFn<A extends any[], E>( | ||
f: (...args: A) => Promise<Err<E>>, | ||
): (...args: A) => PromiseResult<never, E> | ||
export function asyncFn<A extends any[], T, E>( | ||
f: (...args: A) => Promise<Ok<T> | Err<E>>, | ||
): (...args: A) => PromiseResult<T, E> | ||
export function asyncFn<A extends any[], T, E>( | ||
f: (...args: A) => Promise<Result<T, E>>, | ||
): (...args: A) => PromiseResult<T, E> | ||
export function asyncFn<A extends any[], T, E>( | ||
f: (...args: A) => PromiseResult<T, E>, | ||
): (...args: A) => PromiseResult<T, E> | ||
export function asyncFn<A extends any[], T, E>( | ||
f: (...args: A) => Promise<Ok<T> | Err<E> | Result<T, E>> | PromiseResult<T, E>, | ||
): (...args: A) => PromiseResult<T, E> { | ||
return function (...args: A) { | ||
return new PromiseResult<T, E>(f(...args)) | ||
export function asyncFn<A extends any[], R extends PromiseResult<any, any>>( | ||
f: (...args: A) => R, | ||
): (...args: A) => PromiseResult<InferOk<Awaited<R>>, InferErr<Awaited<R>>> | ||
export function asyncFn<A extends any[], R extends Promise<Result<any, any>>>( | ||
f: (...args: A) => R, | ||
): (...args: A) => PromiseResult<InferOk<Awaited<R>>, InferErr<Awaited<R>>> | ||
export function asyncFn(f: any): any { | ||
return function (...args: any[]) { | ||
return new PromiseResult(f(...args)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters