Skip to content

Commit

Permalink
feat(api): add async types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 2, 2024
1 parent 4fe9761 commit 35ad820
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/api/package.json
Expand Up @@ -81,6 +81,9 @@
"./assoc": {
"default": "./assoc.js"
},
"./async": {
"default": "./async.js"
},
"./bind": {
"default": "./bind.js"
},
Expand Down
24 changes: 24 additions & 0 deletions packages/api/src/async.ts
@@ -0,0 +1,24 @@
import type { Fn, Fn0, Fn2 } from "./fn.js";

export type MaybePromise<T> = T | Promise<T>;

export type MaybeAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;

export type MaybeAsyncGenerator<T> =
| IterableIterator<T>
| AsyncIterableIterator<T>;

export type AsyncPredicate<T> = Fn<T, Promise<boolean>>;

export type AsyncPredicate2<T> = Fn2<T, T, Promise<boolean>>;

export type AsyncStatefulPredicate<T> = Fn0<AsyncPredicate<T>>;

export type AsyncStatefulPredicate2<T> = Fn0<AsyncPredicate2<T>>;

/**
* Async version of {@link identity}.
*
* @param x
*/
export const asyncIdentity = async <T>(x: T) => x;
1 change: 1 addition & 0 deletions packages/api/src/index.ts
@@ -1,4 +1,5 @@
export * from "./assoc.js";
export * from "./async.js";
export * from "./bind.js";
export * from "./buffered.js";
export * from "./clear.js";
Expand Down

0 comments on commit 35ad820

Please sign in to comment.