@thi.ng/compose 2.1.71 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-03-27T09:53:45Z
3
+ - **Last updated**: 2024-04-11T12:32:44Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,23 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ # [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/compose@3.0.0) (2024-04-08)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - remove/migrate delay() to different pkg ([745abbb](https://github.com/thi-ng/umbrella/commit/745abbb))
17
+ - BREAKING CHANGE: migrate delay() & Delay class to [@thi.ng/memoize](https://github.com/thi-ng/umbrella/tree/main/packages/memoize)
18
+ - see [d8f4733c05e724c38195f209337d0a015e049ac4](https://github.com/thi-ng/umbrella/commit/d8f4733c05e724c38195f209337d0a015e049ac4) for details
19
+
20
+ #### 🚀 Features
21
+
22
+ - add async composition helpers ([168ea42](https://github.com/thi-ng/umbrella/commit/168ea42))
23
+ - add async functions:
24
+ - compAsync()
25
+ - juxtAsync()
26
+ - threadFirstAsync()/threadLastAsync()
27
+ - trampolineAsync()
28
+
12
29
  ### [2.1.35](https://github.com/thi-ng/umbrella/tree/@thi.ng/compose@2.1.35) (2023-08-04)
13
30
 
14
31
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 190 standalone projects, maintained as part
10
+ > This is one of 192 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -15,6 +15,8 @@
15
15
  > GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
16
16
 
17
17
  - [About](#about)
18
+ - [Composition helpers](#composition-helpers)
19
+ - [Async functions](#async-functions)
18
20
  - [Status](#status)
19
21
  - [Installation](#installation)
20
22
  - [Dependencies](#dependencies)
@@ -27,6 +29,28 @@
27
29
 
28
30
  Optimized functional composition helpers.
29
31
 
32
+ ## Composition helpers
33
+
34
+ - [comp()](https://docs.thi.ng/umbrella/compose/functions/comp.html)
35
+ - [compLeft()](https://docs.thi.ng/umbrella/compose/functions/compLeft.html)
36
+ - [complement()](https://docs.thi.ng/umbrella/compose/functions/complement.html)
37
+ - [constantly()](https://docs.thi.ng/umbrella/compose/functions/constantly.html)
38
+ - [juxt()](https://docs.thi.ng/umbrella/compose/functions/juxt.html)
39
+ - [partial()](https://docs.thi.ng/umbrella/compose/functions/partial.html)
40
+ - [threadFirst()](https://docs.thi.ng/umbrella/compose/functions/threadFirst.html)
41
+ - [threadLast()](https://docs.thi.ng/umbrella/compose/functions/threadLast.html)
42
+ - [trampoline()](https://docs.thi.ng/umbrella/compose/functions/trampoline.html)
43
+
44
+ ### Async functions
45
+
46
+ - [compAsync()](https://docs.thi.ng/umbrella/compose/functions/compAsync.html)
47
+ - [delayed()](https://docs.thi.ng/umbrella/compose/functions/delayed.html)
48
+ - [juxtAsync()](https://docs.thi.ng/umbrella/compose/functions/juxtAsync.html)
49
+ - [promisify()](https://docs.thi.ng/umbrella/compose/functions/promisify.html)
50
+ - [threadFirstAsync()](https://docs.thi.ng/umbrella/compose/functions/threadFirstAsync.html)
51
+ - [threadLastAsync()](https://docs.thi.ng/umbrella/compose/functions/threadLastAsync.html)
52
+ - [trampolineAsync()](https://docs.thi.ng/umbrella/compose/functions/trampolineAsync.html)
53
+
30
54
  ## Status
31
55
 
32
56
  **STABLE** - used in production
@@ -39,7 +63,13 @@ Optimized functional composition helpers.
39
63
  yarn add @thi.ng/compose
40
64
  ```
41
65
 
42
- ES module import:
66
+ ESM import:
67
+
68
+ ```ts
69
+ import * as comp from "@thi.ng/compose";
70
+ ```
71
+
72
+ Browser ESM import:
43
73
 
44
74
  ```html
45
75
  <script type="module" src="https://cdn.skypack.dev/@thi.ng/compose"></script>
@@ -50,10 +80,10 @@ ES module import:
50
80
  For Node.js REPL:
51
81
 
52
82
  ```js
53
- const compose = await import("@thi.ng/compose");
83
+ const comp = await import("@thi.ng/compose");
54
84
  ```
55
85
 
56
- Package sizes (brotli'd, pre-treeshake): ESM: 858 bytes
86
+ Package sizes (brotli'd, pre-treeshake): ESM: 815 bytes
57
87
 
58
88
  ## Dependencies
59
89
 
@@ -75,14 +105,6 @@ directory are using this package:
75
105
 
76
106
  [Generated API docs](https://docs.thi.ng/umbrella/compose/)
77
107
 
78
- - [comp()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/comp.ts)
79
- - [compL()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/comp.ts#L52)
80
- - [juxt()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/juxt.ts)
81
- - [partial()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/partial.ts)
82
- - [threadFirst()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/thread-first.ts)
83
- - [threadLast()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/thread-last.ts)
84
- - [trampoline()](https://github.com/thi-ng/umbrella/tree/develop/packages/compose/src/trampoline.ts)
85
-
86
108
  ## Authors
87
109
 
88
110
  - [Karsten Schmidt](https://thi.ng)
package/comp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Fn, FnAny } from "@thi.ng/api";
1
+ import type { Fn, FnA, FnAny, FnAnyA } from "@thi.ng/api";
2
2
  /**
3
3
  * Returns the right-to-left composition of given functions. I.e. when
4
4
  * the composed function is called, the given right most function is
@@ -20,19 +20,33 @@ export declare function comp<A, B, C, D, E, F, G, H, I, J>(a: Fn<B, A>, b: Fn<C,
20
20
  /**
21
21
  * Similar to {@link comp}, but composes given functions in left-to-right order.
22
22
  */
23
- export declare function compL<A>(a: FnAny<A>): FnAny<A>;
24
- export declare function compL<A, B>(a: FnAny<A>, b: Fn<A, B>): FnAny<B>;
25
- export declare function compL<A, B, C>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>): FnAny<C>;
26
- export declare function compL<A, B, C, D>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>): FnAny<D>;
27
- export declare function compL<A, B, C, D, E>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>): FnAny<E>;
28
- export declare function compL<A, B, C, D, E, F>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>): FnAny<F>;
29
- export declare function compL<A, B, C, D, E, F, G>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>): FnAny<G>;
30
- export declare function compL<A, B, C, D, E, F, G, H>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>): FnAny<H>;
31
- export declare function compL<A, B, C, D, E, F, G, H, I>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>): FnAny<I>;
32
- export declare function compL<A, B, C, D, E, F, G, H, I, J>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>, j: Fn<I, J>): FnAny<J>;
33
- export declare function compL<A, B, C, D, E, F, G, H, I, J>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>, j: Fn<I, J>, ...xs: Fn<any, any>[]): FnAny<any>;
23
+ export declare function compLeft<A>(a: FnAny<A>): FnAny<A>;
24
+ export declare function compLeft<A, B>(a: FnAny<A>, b: Fn<A, B>): FnAny<B>;
25
+ export declare function compLeft<A, B, C>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>): FnAny<C>;
26
+ export declare function compLeft<A, B, C, D>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>): FnAny<D>;
27
+ export declare function compLeft<A, B, C, D, E>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>): FnAny<E>;
28
+ export declare function compLeft<A, B, C, D, E, F>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>): FnAny<F>;
29
+ export declare function compLeft<A, B, C, D, E, F, G>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>): FnAny<G>;
30
+ export declare function compLeft<A, B, C, D, E, F, G, H>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>): FnAny<H>;
31
+ export declare function compLeft<A, B, C, D, E, F, G, H, I>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>): FnAny<I>;
32
+ export declare function compLeft<A, B, C, D, E, F, G, H, I, J>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>, j: Fn<I, J>): FnAny<J>;
33
+ export declare function compLeft<A, B, C, D, E, F, G, H, I, J>(a: FnAny<A>, b: Fn<A, B>, c: Fn<B, C>, d: Fn<C, D>, e: Fn<D, E>, f: Fn<E, F>, g: Fn<F, G>, h: Fn<G, H>, i: Fn<H, I>, j: Fn<I, J>, ...xs: Fn<any, any>[]): FnAny<any>;
34
34
  /**
35
- * @deprecated renamed to {@link compL}
35
+ * @deprecated renamed to {@link compLeft}.
36
36
  */
37
- export declare const compI: typeof compL;
37
+ export declare const compL: typeof compLeft;
38
+ /**
39
+ * Async version of {@link comp}.
40
+ */
41
+ export declare function compAsync<A, B>(a: FnAnyA<A>): FnAnyA<A>;
42
+ export declare function compAsync<A, B>(a: FnA<B, A>, b: FnAnyA<B>): FnAnyA<A>;
43
+ export declare function compAsync<A, B, C>(a: FnA<B, A>, b: FnA<C, B>, c: FnAnyA<C>): FnAnyA<A>;
44
+ export declare function compAsync<A, B, C, D>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnAnyA<D>): FnAnyA<A>;
45
+ export declare function compAsync<A, B, C, D, E>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnAnyA<D>): FnAnyA<A>;
46
+ export declare function compAsync<A, B, C, D, E, F>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnAnyA<F>): FnAnyA<A>;
47
+ export declare function compAsync<A, B, C, D, E, F, G>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnA<G, F>, g: FnAnyA<G>): FnAnyA<A>;
48
+ export declare function compAsync<A, B, C, D, E, F, G, H>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnA<G, F>, g: FnA<H, G>, h: FnAnyA<H>): FnAnyA<A>;
49
+ export declare function compAsync<A, B, C, D, E, F, G, H, I>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnA<G, F>, g: FnA<H, G>, h: FnA<I, H>, i: FnAnyA<I>): FnAnyA<A>;
50
+ export declare function compAsync<A, B, C, D, E, F, G, H, I, J>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnA<G, F>, g: FnA<H, G>, h: FnA<I, H>, i: FnA<J, I>, j: FnAnyA<J>): FnAnyA<A>;
51
+ export declare function compAsync<A, B, C, D, E, F, G, H, I, J>(a: FnA<B, A>, b: FnA<C, B>, c: FnA<D, C>, d: FnA<E, D>, e: FnA<F, E>, f: FnA<G, F>, g: FnA<H, G>, h: FnA<I, H>, i: FnA<J, I>, j: FnA<any, J>, ...fns: FnAnyA<any>[]): FnAnyA<A>;
38
52
  //# sourceMappingURL=comp.d.ts.map
package/comp.js CHANGED
@@ -28,12 +28,23 @@ function comp(...fns) {
28
28
  return fns.length === 10 ? fn : comp(fn, ...fns.slice(10));
29
29
  }
30
30
  }
31
- function compL(...fns) {
31
+ function compLeft(...fns) {
32
32
  return comp.apply(null, fns.reverse());
33
33
  }
34
- const compI = compL;
34
+ const compL = compLeft;
35
+ function compAsync(...fns) {
36
+ return async (...xs) => {
37
+ let n = fns.length - 1;
38
+ let res = fns[n](...xs);
39
+ while (n-- > 0) {
40
+ res = await fns[n](res);
41
+ }
42
+ return res;
43
+ };
44
+ }
35
45
  export {
36
46
  comp,
37
- compI,
38
- compL
47
+ compAsync,
48
+ compL,
49
+ compLeft
39
50
  };
package/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./comp.js";
2
2
  export * from "./complement.js";
3
3
  export * from "./constantly.js";
4
- export * from "./delay.js";
5
4
  export * from "./delayed.js";
6
5
  export * from "./identity.js";
7
6
  export * from "./ifdef.js";
package/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./comp.js";
2
2
  export * from "./complement.js";
3
3
  export * from "./constantly.js";
4
- export * from "./delay.js";
5
4
  export * from "./delayed.js";
6
5
  export * from "./identity.js";
7
6
  export * from "./ifdef.js";
package/juxt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Fn } from "@thi.ng/api";
1
+ import type { Fn, FnA } from "@thi.ng/api";
2
2
  export declare function juxt<T, A>(a: Fn<T, A>): Fn<T, [A]>;
3
3
  export declare function juxt<T, A, B>(a: Fn<T, A>, b: Fn<T, B>): Fn<T, [A, B]>;
4
4
  export declare function juxt<T, A, B, C>(a: Fn<T, A>, b: Fn<T, B>, c: Fn<T, C>): Fn<T, [A, B, C]>;
@@ -8,4 +8,20 @@ export declare function juxt<T, A, B, C, D, E, F>(a: Fn<T, A>, b: Fn<T, B>, c: F
8
8
  export declare function juxt<T, A, B, C, D, E, F, G>(a: Fn<T, A>, b: Fn<T, B>, c: Fn<T, C>, d: Fn<T, D>, e: Fn<T, E>, f: Fn<T, F>, g: Fn<T, G>): Fn<T, [A, B, C, D, E, F, G]>;
9
9
  export declare function juxt<T, A, B, C, D, E, F, G, H>(a: Fn<T, A>, b: Fn<T, B>, c: Fn<T, C>, d: Fn<T, D>, e: Fn<T, E>, f: Fn<T, F>, g: Fn<T, G>, h: Fn<T, H>): Fn<T, [A, B, C, D, E, F, G, H]>;
10
10
  export declare function juxt<T, A, B, C, D, E, F, G, H>(a: Fn<T, A>, b: Fn<T, B>, c: Fn<T, C>, d: Fn<T, D>, e: Fn<T, E>, f: Fn<T, F>, g: Fn<T, G>, h: Fn<T, H>, ...xs: Fn<T, any>[]): Fn<T, any[]>;
11
+ /**
12
+ * Async version of {@link juxt}. Returns an async function which takes a single
13
+ * arg `x`, calls all given functions with `x` and then waits for all results
14
+ * before returning them as tuple.
15
+ *
16
+ * @param a
17
+ */
18
+ export declare function juxtAsync<T, A>(a: FnA<T, A>): FnA<T, [A]>;
19
+ export declare function juxtAsync<T, A, B>(a: FnA<T, A>, b: FnA<T, B>): FnA<T, [A, B]>;
20
+ export declare function juxtAsync<T, A, B, C>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>): FnA<T, [A, B, C]>;
21
+ export declare function juxtAsync<T, A, B, C, D>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>): FnA<T, [A, B, C, D]>;
22
+ export declare function juxtAsync<T, A, B, C, D, E>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>, e: FnA<T, E>): FnA<T, [A, B, C, D, E]>;
23
+ export declare function juxtAsync<T, A, B, C, D, E, F>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>, e: FnA<T, E>, f: FnA<T, F>): FnA<T, [A, B, C, D, E, F]>;
24
+ export declare function juxtAsync<T, A, B, C, D, E, F, G>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>, e: FnA<T, E>, f: FnA<T, F>, g: FnA<T, G>): FnA<T, [A, B, C, D, E, F, G]>;
25
+ export declare function juxtAsync<T, A, B, C, D, E, F, G, H>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>, e: FnA<T, E>, f: FnA<T, F>, g: FnA<T, G>, h: FnA<T, H>): FnA<T, [A, B, C, D, E, F, G, H]>;
26
+ export declare function juxtAsync<T, A, B, C, D, E, F, G, H>(a: FnA<T, A>, b: FnA<T, B>, c: FnA<T, C>, d: FnA<T, D>, e: FnA<T, E>, f: FnA<T, F>, g: FnA<T, G>, h: FnA<T, H>, ...xs: FnA<T, any>[]): FnA<T, any[]>;
11
27
  //# sourceMappingURL=juxt.d.ts.map
package/juxt.js CHANGED
@@ -27,6 +27,10 @@ function juxt(...fns) {
27
27
  };
28
28
  }
29
29
  }
30
+ function juxtAsync(...fns) {
31
+ return async (x) => await Promise.all(fns.map((f) => f(x)));
32
+ }
30
33
  export {
31
- juxt
34
+ juxt,
35
+ juxtAsync
32
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/compose",
3
- "version": "2.1.71",
3
+ "version": "3.0.1",
4
4
  "description": "Optimized functional composition helpers",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,8 +36,8 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.9.31",
40
- "@thi.ng/errors": "^2.5.2"
39
+ "@thi.ng/api": "^8.10.1",
40
+ "@thi.ng/errors": "^2.5.4"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.43.0",
@@ -75,9 +75,6 @@
75
75
  "./constantly": {
76
76
  "default": "./constantly.js"
77
77
  },
78
- "./delay": {
79
- "default": "./delay.js"
80
- },
81
78
  "./delayed": {
82
79
  "default": "./delayed.js"
83
80
  },
@@ -106,5 +103,8 @@
106
103
  "default": "./trampoline.js"
107
104
  }
108
105
  },
109
- "gitHead": "feb3b24654f2c931cd3c3308c1c0c807ee14d0e4\n"
106
+ "thi.ng": {
107
+ "alias": "comp"
108
+ },
109
+ "gitHead": "18a0c063a7b33d790e5bc2486c106f45f663ac28\n"
110
110
  }
package/thread-first.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FnAny } from "@thi.ng/api";
1
+ import type { FnAny, FnAnyA, MaybePromise } from "@thi.ng/api";
2
2
  /**
3
3
  * Similar to {@link threadLast}. A dataflow operator to improve the legibility
4
4
  * of long (or deeply nested) call expressions. Takes an `init` value and a
@@ -38,4 +38,14 @@ import type { FnAny } from "@thi.ng/api";
38
38
  * @param fns - functions / S-expressions
39
39
  */
40
40
  export declare const threadFirst: (init: any, ...fns: (FnAny<any> | [FnAny<any>, ...any[]])[]) => any;
41
+ /**
42
+ * Async version of {@link threadFirst}.
43
+ *
44
+ * @remarks
45
+ * Also see {@link threadLastAsync}.
46
+ *
47
+ * @param init
48
+ * @param fns
49
+ */
50
+ export declare const threadFirstAsync: (init: MaybePromise<any>, ...fns: (FnAnyA<any> | [FnAnyA<any>, ...any[]])[]) => Promise<any>;
41
51
  //# sourceMappingURL=thread-first.d.ts.map
package/thread-first.js CHANGED
@@ -2,6 +2,14 @@ const threadFirst = (init, ...fns) => fns.reduce(
2
2
  (acc, expr) => typeof expr === "function" ? expr(acc) : expr[0](acc, ...expr.slice(1)),
3
3
  init
4
4
  );
5
+ const threadFirstAsync = async (init, ...fns) => {
6
+ let res = await init;
7
+ for (let expr of fns) {
8
+ res = await (typeof expr === "function" ? expr(res) : expr[0](res, ...expr.slice(1)));
9
+ }
10
+ return res;
11
+ };
5
12
  export {
6
- threadFirst
13
+ threadFirst,
14
+ threadFirstAsync
7
15
  };
package/thread-last.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FnAny } from "@thi.ng/api";
1
+ import type { FnAny, FnAnyA, MaybePromise } from "@thi.ng/api";
2
2
  /**
3
3
  * Similar to {@link threadFirst}. A dataflow operator to improve the legibility
4
4
  * of long (or deeply nested) call expressions. Takes an `init` value and a
@@ -38,4 +38,14 @@ import type { FnAny } from "@thi.ng/api";
38
38
  * @param fns - functions / S-expressions
39
39
  */
40
40
  export declare const threadLast: (init: any, ...fns: (FnAny<any> | [FnAny<any>, ...any[]])[]) => any;
41
+ /**
42
+ * Async version of {@link threadLast}.
43
+ *
44
+ * @remarks
45
+ * Also see {@link threadFirstAsync}.
46
+ *
47
+ * @param init
48
+ * @param fns
49
+ */
50
+ export declare const threadLastAsync: (init: MaybePromise<any>, ...fns: (FnAnyA<any> | [FnAnyA<any>, ...any[]])[]) => Promise<any>;
41
51
  //# sourceMappingURL=thread-last.d.ts.map
package/thread-last.js CHANGED
@@ -2,6 +2,14 @@ const threadLast = (init, ...fns) => fns.reduce(
2
2
  (acc, expr) => typeof expr === "function" ? expr(acc) : expr[0](...expr.slice(1), acc),
3
3
  init
4
4
  );
5
+ const threadLastAsync = async (init, ...fns) => {
6
+ let res = await init;
7
+ for (let expr of fns) {
8
+ res = await (typeof expr === "function" ? expr(res) : expr[0](...expr.slice(1), res));
9
+ }
10
+ return res;
11
+ };
5
12
  export {
6
- threadLast
13
+ threadLast,
14
+ threadLastAsync
7
15
  };
package/trampoline.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Fn0 } from "@thi.ng/api";
1
+ import type { Fn0, Fn0A, MaybePromise } from "@thi.ng/api";
2
2
  /**
3
3
  * Takes a function returning either a no-arg function (thunk) or its
4
4
  * already realized (non-function) result. Re-executes thunk for as long
@@ -32,4 +32,10 @@ import type { Fn0 } from "@thi.ng/api";
32
32
  * @param f - function
33
33
  */
34
34
  export declare const trampoline: <T>(f: T | Fn0<T | Fn0<T>>) => T;
35
+ /**
36
+ * Async version of {@link trampoline}.
37
+ *
38
+ * @param f - function
39
+ */
40
+ export declare const trampolineAsync: <T>(f: MaybePromise<T | Fn0A<T | Fn0A<T>>>) => Promise<T>;
35
41
  //# sourceMappingURL=trampoline.d.ts.map
package/trampoline.js CHANGED
@@ -4,6 +4,14 @@ const trampoline = (f) => {
4
4
  }
5
5
  return f;
6
6
  };
7
+ const trampolineAsync = async (f) => {
8
+ f = await f;
9
+ while (typeof f === "function") {
10
+ f = await f();
11
+ }
12
+ return f;
13
+ };
7
14
  export {
8
- trampoline
15
+ trampoline,
16
+ trampolineAsync
9
17
  };
package/delay.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { Fn0, IDeref } from "@thi.ng/api";
2
- export declare const delay: <T>(body: Fn0<T>) => Delay<T>;
3
- export declare class Delay<T> implements IDeref<T> {
4
- protected value: T;
5
- protected body: Fn0<T>;
6
- protected realized: boolean;
7
- constructor(body: Fn0<T>);
8
- deref(): T;
9
- isRealized(): boolean;
10
- }
11
- //# sourceMappingURL=delay.d.ts.map
package/delay.js DELETED
@@ -1,24 +0,0 @@
1
- const delay = (body) => new Delay(body);
2
- class Delay {
3
- value;
4
- body;
5
- realized;
6
- constructor(body) {
7
- this.body = body;
8
- this.realized = false;
9
- }
10
- deref() {
11
- if (!this.realized) {
12
- this.value = this.body();
13
- this.realized = true;
14
- }
15
- return this.value;
16
- }
17
- isRealized() {
18
- return this.realized;
19
- }
20
- }
21
- export {
22
- Delay,
23
- delay
24
- };