From 35ad82091dd1aeb40dbc6da88e6199a4303ff5a0 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 2 Apr 2024 14:32:11 +0200 Subject: [PATCH] feat(api): add async types --- packages/api/package.json | 3 +++ packages/api/src/async.ts | 24 ++++++++++++++++++++++++ packages/api/src/index.ts | 1 + 3 files changed, 28 insertions(+) create mode 100644 packages/api/src/async.ts diff --git a/packages/api/package.json b/packages/api/package.json index ac29383b9f..8483c0a313 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -81,6 +81,9 @@ "./assoc": { "default": "./assoc.js" }, + "./async": { + "default": "./async.js" + }, "./bind": { "default": "./bind.js" }, diff --git a/packages/api/src/async.ts b/packages/api/src/async.ts new file mode 100644 index 0000000000..6512d71f33 --- /dev/null +++ b/packages/api/src/async.ts @@ -0,0 +1,24 @@ +import type { Fn, Fn0, Fn2 } from "./fn.js"; + +export type MaybePromise = T | Promise; + +export type MaybeAsyncIterable = Iterable | AsyncIterable; + +export type MaybeAsyncGenerator = + | IterableIterator + | AsyncIterableIterator; + +export type AsyncPredicate = Fn>; + +export type AsyncPredicate2 = Fn2>; + +export type AsyncStatefulPredicate = Fn0>; + +export type AsyncStatefulPredicate2 = Fn0>; + +/** + * Async version of {@link identity}. + * + * @param x + */ +export const asyncIdentity = async (x: T) => x; diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 154bfbe5d1..d26d5b70d1 100644 --- a/packages/api/src/index.ts +++ b/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";