@thi.ng/compose 2.1.50 → 2.1.51

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**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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.
package/comp.js CHANGED
@@ -1,37 +1,39 @@
1
1
  import { illegalArity } from "@thi.ng/errors/illegal-arity";
2
- export function comp(...fns) {
3
- let [a, b, c, d, e, f, g, h, i, j] = fns;
4
- switch (fns.length) {
5
- case 0:
6
- illegalArity(0);
7
- case 1:
8
- return a;
9
- case 2:
10
- return (...xs) => a(b(...xs));
11
- case 3:
12
- return (...xs) => a(b(c(...xs)));
13
- case 4:
14
- return (...xs) => a(b(c(d(...xs))));
15
- case 5:
16
- return (...xs) => a(b(c(d(e(...xs)))));
17
- case 6:
18
- return (...xs) => a(b(c(d(e(f(...xs))))));
19
- case 7:
20
- return (...xs) => a(b(c(d(e(f(g(...xs)))))));
21
- case 8:
22
- return (...xs) => a(b(c(d(e(f(g(h(...xs))))))));
23
- case 9:
24
- return (...xs) => a(b(c(d(e(f(g(h(i(...xs)))))))));
25
- case 10:
26
- default:
27
- const fn = (...xs) => a(b(c(d(e(f(g(h(i(j(...xs))))))))));
28
- return fns.length === 10 ? fn : comp(fn, ...fns.slice(10));
29
- }
2
+ function comp(...fns) {
3
+ let [a, b, c, d, e, f, g, h, i, j] = fns;
4
+ switch (fns.length) {
5
+ case 0:
6
+ illegalArity(0);
7
+ case 1:
8
+ return a;
9
+ case 2:
10
+ return (...xs) => a(b(...xs));
11
+ case 3:
12
+ return (...xs) => a(b(c(...xs)));
13
+ case 4:
14
+ return (...xs) => a(b(c(d(...xs))));
15
+ case 5:
16
+ return (...xs) => a(b(c(d(e(...xs)))));
17
+ case 6:
18
+ return (...xs) => a(b(c(d(e(f(...xs))))));
19
+ case 7:
20
+ return (...xs) => a(b(c(d(e(f(g(...xs)))))));
21
+ case 8:
22
+ return (...xs) => a(b(c(d(e(f(g(h(...xs))))))));
23
+ case 9:
24
+ return (...xs) => a(b(c(d(e(f(g(h(i(...xs)))))))));
25
+ case 10:
26
+ default:
27
+ const fn = (...xs) => a(b(c(d(e(f(g(h(i(j(...xs))))))))));
28
+ return fns.length === 10 ? fn : comp(fn, ...fns.slice(10));
29
+ }
30
30
  }
31
- export function compL(...fns) {
32
- return comp.apply(null, fns.reverse());
31
+ function compL(...fns) {
32
+ return comp.apply(null, fns.reverse());
33
33
  }
34
- /**
35
- * @deprecated renamed to {@link compL}
36
- */
37
- export const compI = compL;
34
+ const compI = compL;
35
+ export {
36
+ comp,
37
+ compI,
38
+ compL
39
+ };
package/complement.js CHANGED
@@ -1,3 +1,6 @@
1
- export function complement(f) {
2
- return (...xs) => !f(...xs);
1
+ function complement(f) {
2
+ return (...xs) => !f(...xs);
3
3
  }
4
+ export {
5
+ complement
6
+ };
package/constantly.js CHANGED
@@ -1 +1,4 @@
1
- export const constantly = (x) => () => x;
1
+ const constantly = (x) => () => x;
2
+ export {
3
+ constantly
4
+ };
package/delay.js CHANGED
@@ -1,20 +1,24 @@
1
- export const delay = (body) => new Delay(body);
2
- export 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;
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;
19
14
  }
15
+ return this.value;
16
+ }
17
+ isRealized() {
18
+ return this.realized;
19
+ }
20
20
  }
21
+ export {
22
+ Delay,
23
+ delay
24
+ };
package/delayed.js CHANGED
@@ -1 +1,4 @@
1
- export const delayed = (x, t) => new Promise((resolve) => setTimeout(() => resolve(x), t));
1
+ const delayed = (x, t) => new Promise((resolve) => setTimeout(() => resolve(x), t));
2
+ export {
3
+ delayed
4
+ };
package/identity.js CHANGED
@@ -1,6 +1,4 @@
1
- /**
2
- * Same as eponymous function in thi.ng/api. Identity function: `(x) => x`.
3
- *
4
- * @param x
5
- */
6
- export const identity = (x) => x;
1
+ const identity = (x) => x;
2
+ export {
3
+ identity
4
+ };
package/ifdef.js CHANGED
@@ -1,7 +1,4 @@
1
- /**
2
- * Returns f(x) iff `x` is not null or undefined.
3
- *
4
- * @param f - function
5
- * @param x - value
6
- */
7
- export const ifDef = (f, x) => x != null ? f(x) : undefined;
1
+ const ifDef = (f, x) => x != null ? f(x) : void 0;
2
+ export {
3
+ ifDef
4
+ };
package/juxt.js CHANGED
@@ -1,29 +1,32 @@
1
- export function juxt(...fns) {
2
- const [a, b, c, d, e, f, g, h] = fns;
3
- switch (fns.length) {
4
- case 1:
5
- return (x) => [a(x)];
6
- case 2:
7
- return (x) => [a(x), b(x)];
8
- case 3:
9
- return (x) => [a(x), b(x), c(x)];
10
- case 4:
11
- return (x) => [a(x), b(x), c(x), d(x)];
12
- case 5:
13
- return (x) => [a(x), b(x), c(x), d(x), e(x)];
14
- case 6:
15
- return (x) => [a(x), b(x), c(x), d(x), e(x), f(x)];
16
- case 7:
17
- return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x)];
18
- case 8:
19
- return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x), h(x)];
20
- default:
21
- return (x) => {
22
- let res = new Array(fns.length);
23
- for (let i = fns.length; i-- > 0;) {
24
- res[i] = fns[i](x);
25
- }
26
- return res;
27
- };
28
- }
1
+ function juxt(...fns) {
2
+ const [a, b, c, d, e, f, g, h] = fns;
3
+ switch (fns.length) {
4
+ case 1:
5
+ return (x) => [a(x)];
6
+ case 2:
7
+ return (x) => [a(x), b(x)];
8
+ case 3:
9
+ return (x) => [a(x), b(x), c(x)];
10
+ case 4:
11
+ return (x) => [a(x), b(x), c(x), d(x)];
12
+ case 5:
13
+ return (x) => [a(x), b(x), c(x), d(x), e(x)];
14
+ case 6:
15
+ return (x) => [a(x), b(x), c(x), d(x), e(x), f(x)];
16
+ case 7:
17
+ return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x)];
18
+ case 8:
19
+ return (x) => [a(x), b(x), c(x), d(x), e(x), f(x), g(x), h(x)];
20
+ default:
21
+ return (x) => {
22
+ let res = new Array(fns.length);
23
+ for (let i = fns.length; i-- > 0; ) {
24
+ res[i] = fns[i](x);
25
+ }
26
+ return res;
27
+ };
28
+ }
29
29
  }
30
+ export {
31
+ juxt
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/compose",
3
- "version": "2.1.50",
3
+ "version": "2.1.51",
4
4
  "description": "Optimized functional composition helpers",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,11 +35,12 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/errors": "^2.4.5"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/errors": "^2.4.6"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@microsoft/api-extractor": "^7.38.3",
43
+ "esbuild": "^0.19.8",
41
44
  "rimraf": "^5.0.5",
42
45
  "tools": "^0.0.1",
43
46
  "typedoc": "^0.25.4",
@@ -103,5 +106,5 @@
103
106
  "default": "./trampoline.js"
104
107
  }
105
108
  },
106
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
109
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
107
110
  }
package/partial.js CHANGED
@@ -1,24 +1,27 @@
1
1
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
2
- export function partial(fn, ...args) {
3
- let [a, b, c, d, e, f, g, h] = args;
4
- switch (args.length) {
5
- case 1:
6
- return (...xs) => fn(a, ...xs);
7
- case 2:
8
- return (...xs) => fn(a, b, ...xs);
9
- case 3:
10
- return (...xs) => fn(a, b, c, ...xs);
11
- case 4:
12
- return (...xs) => fn(a, b, c, d, ...xs);
13
- case 5:
14
- return (...xs) => fn(a, b, c, d, e, ...xs);
15
- case 6:
16
- return (...xs) => fn(a, b, c, d, e, f, ...xs);
17
- case 7:
18
- return (...xs) => fn(a, b, c, d, e, f, g, ...xs);
19
- case 8:
20
- return (...xs) => fn(a, b, c, d, e, f, g, h, ...xs);
21
- default:
22
- illegalArgs();
23
- }
2
+ function partial(fn, ...args) {
3
+ let [a, b, c, d, e, f, g, h] = args;
4
+ switch (args.length) {
5
+ case 1:
6
+ return (...xs) => fn(a, ...xs);
7
+ case 2:
8
+ return (...xs) => fn(a, b, ...xs);
9
+ case 3:
10
+ return (...xs) => fn(a, b, c, ...xs);
11
+ case 4:
12
+ return (...xs) => fn(a, b, c, d, ...xs);
13
+ case 5:
14
+ return (...xs) => fn(a, b, c, d, e, ...xs);
15
+ case 6:
16
+ return (...xs) => fn(a, b, c, d, e, f, ...xs);
17
+ case 7:
18
+ return (...xs) => fn(a, b, c, d, e, f, g, ...xs);
19
+ case 8:
20
+ return (...xs) => fn(a, b, c, d, e, f, g, h, ...xs);
21
+ default:
22
+ illegalArgs();
23
+ }
24
24
  }
25
+ export {
26
+ partial
27
+ };
package/promisify.js CHANGED
@@ -1,19 +1,6 @@
1
- /**
2
- * Takes a function accepting a NodeJS-like callback w/ (error, result)
3
- * args and converts it into a Promise, e.g. for use in async contexts.
4
- *
5
- * @remarks
6
- * The constructed promise calls the given function with a custom
7
- * callback, which then either resolves or rejects the promise.
8
- *
9
- * @example
10
- * ```ts
11
- * (async () => {
12
- * const body = await promisify(partial(fs.readFile, "foo.txt"));
13
- * console.log(body.toString());
14
- * })();
15
- * ```
16
- *
17
- * @param fn - function accepting a callback
18
- */
19
- export const promisify = (fn) => new Promise((resolve, reject) => fn((err, result) => (err != null ? reject(err) : resolve(result))));
1
+ const promisify = (fn) => new Promise(
2
+ (resolve, reject) => fn((err, result) => err != null ? reject(err) : resolve(result))
3
+ );
4
+ export {
5
+ promisify
6
+ };
package/thread-first.js CHANGED
@@ -1,39 +1,7 @@
1
- /**
2
- * Similar to {@link threadLast}. A dataflow operator to improve the legibility
3
- * of long (or deeply nested) call expressions. Takes an `init` value and a
4
- * number of functions and/or function tuples, consisting of: `[fn, ...args]`.
5
- * Executes each function (or tuple) with the return value of the previous
6
- * step/function inserted as **first** argument, using `init` as the first
7
- * expression. Returns result of last function/step given.
8
- *
9
- * @remarks
10
- * This operator allows the code to be read more easily in the order of
11
- * execution (same as the `->` operator/macro in Clojure).
12
- *
13
- * @example
14
- * ```ts
15
- * const neg = (x) => -x;
16
- * const sub = (a, b) => a - b;
17
- * const div = (a, b) => a / b;
18
- *
19
- * // without operator: (-5 - 10) / 20
20
- * console.log(div(sub(neg(5), 10), 20));
21
- * // -0.75
22
- *
23
- * // rewritten using operator:
24
- * threadFirst(
25
- * 5,
26
- * neg, // -5
27
- * [sub, 10], // (-5) - 10
28
- * [div, 20], // (-5 - 10) / 20
29
- * console.log
30
- * );
31
- * // -0.75
32
- * ```
33
- *
34
- * @param init - start value
35
- * @param fns - functions / S-expressions
36
- */
37
- export const threadFirst = (init, ...fns) => fns.reduce((acc, expr) => typeof expr === "function"
38
- ? expr(acc)
39
- : expr[0](acc, ...expr.slice(1)), init);
1
+ const threadFirst = (init, ...fns) => fns.reduce(
2
+ (acc, expr) => typeof expr === "function" ? expr(acc) : expr[0](acc, ...expr.slice(1)),
3
+ init
4
+ );
5
+ export {
6
+ threadFirst
7
+ };
package/thread-last.js CHANGED
@@ -1,39 +1,7 @@
1
- /**
2
- * Similar to {@link threadFirst}. A dataflow operator to improve the legibility
3
- * of long (or deeply nested) call expressions. Takes an `init` value and a
4
- * number of functions and/or function tuples, consisting of: `[fn, ...args]`.
5
- * Executes each function (or tuple) with the return value of the previous
6
- * step/function inserted as **last** argument, using `init` as the first
7
- * expression. Returns result of last function/step given.
8
- *
9
- * @remarks
10
- * This operator allows the code to be read more easily in the order of
11
- * execution (same as the `->>` operator/macro in Clojure).
12
- *
13
- * @example
14
- * ```ts
15
- * const neg = (x) => -x;
16
- * const sub = (a, b) => a - b;
17
- * const div = (a, b) => a / b;
18
- *
19
- * // without operator: 20 / (10 - (-5))
20
- * console.log(div(20, sub(10, neg(5))));
21
- * // 1.3333333333333333
22
- *
23
- * // rewritten using operator:
24
- * threadLast(
25
- * 5,
26
- * neg, // -5
27
- * [sub, 10], // 10 - (-5)
28
- * [div, 20], // 20 / (10 - (-5))
29
- * console.log
30
- * );
31
- * // 1.3333333333333333
32
- * ```
33
- *
34
- * @param init - start value
35
- * @param fns - functions / S-expressions
36
- */
37
- export const threadLast = (init, ...fns) => fns.reduce((acc, expr) => typeof expr === "function"
38
- ? expr(acc)
39
- : expr[0](...expr.slice(1), acc), init);
1
+ const threadLast = (init, ...fns) => fns.reduce(
2
+ (acc, expr) => typeof expr === "function" ? expr(acc) : expr[0](...expr.slice(1), acc),
3
+ init
4
+ );
5
+ export {
6
+ threadLast
7
+ };
package/trampoline.js CHANGED
@@ -1,36 +1,9 @@
1
- /**
2
- * Takes a function returning either a no-arg function (thunk) or its
3
- * already realized (non-function) result. Re-executes thunk for as long
4
- * as it returns another function/thunk. Once a non-function result has
5
- * been produced, `trampoline` returns that value itself.
6
- *
7
- * @remarks
8
- * If the final result should be function, it needs to wrapped (e.g. as
9
- * a 1-elem array).
10
- *
11
- * This function should be used for non-stack consuming recursion. I.e.
12
- * a trampoline is a form of continuation passing style and only ever
13
- * consumes max. 2 extra stack frames, independent from recursion depth.
14
- *
15
- * @example
16
- * ```ts
17
- * const countdown = (acc, x) =>
18
- * x >= 0 ?
19
- * () => (acc.push(x), countdown(acc, x-1)) :
20
- * acc;
21
- *
22
- * trampoline(countdown([], 4))
23
- * // [ 4, 3, 2, 1, 0 ]
24
- *
25
- * trampoline(countdown([], -1))
26
- * // []
27
- * ```
28
- *
29
- * @param f - function
30
- */
31
- export const trampoline = (f) => {
32
- while (typeof f === "function") {
33
- f = f();
34
- }
35
- return f;
1
+ const trampoline = (f) => {
2
+ while (typeof f === "function") {
3
+ f = f();
4
+ }
5
+ return f;
6
+ };
7
+ export {
8
+ trampoline
36
9
  };