@thi.ng/compose 2.1.40 → 2.1.41

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-08-27T11:20:59Z
3
+ - **Last updated**: 2023-08-29T09:49: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/README.md CHANGED
@@ -14,6 +14,7 @@ This project is part of the
14
14
  - [Status](#status)
15
15
  - [Installation](#installation)
16
16
  - [Dependencies](#dependencies)
17
+ - [Usage examples](#usage-examples)
17
18
  - [API](#api)
18
19
  - [Authors](#authors)
19
20
  - [License](#license)
@@ -55,6 +56,18 @@ Package sizes (brotli'd, pre-treeshake): ESM: 751 bytes
55
56
  - [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
56
57
  - [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
57
58
 
59
+ ## Usage examples
60
+
61
+ Several demos in this repo's
62
+ [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
63
+ directory are using this package.
64
+
65
+ A selection:
66
+
67
+ | Screenshot | Description | Live demo | Source |
68
+ |:--------------------------------------------------------------------------------------------------------------------------|:------------------------------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------|
69
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-canvas-basics.jpg" width="240"/> | Minimal rdom-canvas animation | [Demo](https://demo.thi.ng/umbrella/rdom-canvas-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-canvas-basics) |
70
+
58
71
  ## API
59
72
 
60
73
  [Generated API docs](https://docs.thi.ng/umbrella/compose/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/compose",
3
- "version": "2.1.40",
3
+ "version": "2.1.41",
4
4
  "description": "Optimized functional composition helpers",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -105,5 +105,5 @@
105
105
  "default": "./trampoline.js"
106
106
  }
107
107
  },
108
- "gitHead": "5929dd20497668496af13415cdf784a4d6f69aa3\n"
108
+ "gitHead": "9dec130cc636c1da0bc4f2baa0d995579d3b7629\n"
109
109
  }
package/thread-first.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import type { FnAny } from "@thi.ng/api";
2
2
  /**
3
- * Takes an `init` value and a number of functions and/or function
4
- * tuples, consisting of: `[fn, ...args]`. Executes each function
5
- * (or tuple) with the return value of the previous expression inserted
6
- * as first argument, using `init` for the first expression.
3
+ * Similar to {@link threadLast}. A dataflow operator to improve the legibility
4
+ * of long (or deeply nested) call expressions. Takes an `init` value and a
5
+ * number of functions and/or function tuples, consisting of: `[fn, ...args]`.
6
+ * Executes each function (or tuple) with the return value of the previous
7
+ * step/function inserted as **first** argument, using `init` as the first
8
+ * expression. Returns result of last function/step given.
9
+ *
10
+ * @remarks
11
+ * This operator allows the code to be read more easily in the order of
12
+ * execution (same as the `->` operator/macro in Clojure).
7
13
  *
8
14
  * @example
9
15
  * ```ts
@@ -11,18 +17,21 @@ import type { FnAny } from "@thi.ng/api";
11
17
  * const sub = (a, b) => a - b;
12
18
  * const div = (a, b) => a / b;
13
19
  *
20
+ * // without operator: (-5 - 10) / 20
21
+ * console.log(div(sub(neg(5), 10), 20));
22
+ * // -0.75
23
+ *
24
+ * // rewritten using operator:
14
25
  * threadFirst(
15
26
  * 5,
16
27
  * neg, // -5
17
- * [sub, 20], // -5 - 20 = -25
18
- * [div, 10] // -25 / 10 = -2.5
28
+ * [sub, 10], // (-5) - 10
29
+ * [div, 20], // (-5 - 10) / 20
30
+ * console.log
19
31
  * );
20
- *
21
- * // -2.5
32
+ * // -0.75
22
33
  * ```
23
34
  *
24
- * {@link threadLast}
25
- *
26
35
  * @param init - start value
27
36
  * @param fns - functions / S-expressions
28
37
  */
package/thread-first.js CHANGED
@@ -1,8 +1,14 @@
1
1
  /**
2
- * Takes an `init` value and a number of functions and/or function
3
- * tuples, consisting of: `[fn, ...args]`. Executes each function
4
- * (or tuple) with the return value of the previous expression inserted
5
- * as first argument, using `init` for the first expression.
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).
6
12
  *
7
13
  * @example
8
14
  * ```ts
@@ -10,18 +16,21 @@
10
16
  * const sub = (a, b) => a - b;
11
17
  * const div = (a, b) => a / b;
12
18
  *
19
+ * // without operator: (-5 - 10) / 20
20
+ * console.log(div(sub(neg(5), 10), 20));
21
+ * // -0.75
22
+ *
23
+ * // rewritten using operator:
13
24
  * threadFirst(
14
25
  * 5,
15
26
  * neg, // -5
16
- * [sub, 20], // -5 - 20 = -25
17
- * [div, 10] // -25 / 10 = -2.5
27
+ * [sub, 10], // (-5) - 10
28
+ * [div, 20], // (-5 - 10) / 20
29
+ * console.log
18
30
  * );
19
- *
20
- * // -2.5
31
+ * // -0.75
21
32
  * ```
22
33
  *
23
- * {@link threadLast}
24
- *
25
34
  * @param init - start value
26
35
  * @param fns - functions / S-expressions
27
36
  */
package/thread-last.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import type { FnAny } from "@thi.ng/api";
2
2
  /**
3
- * Takes an `init` value and a number of functions and/or function
4
- * tuples, consisting of: `[fn, ...args]`. Executes each function
5
- * (or tuple) with the return value of the previous expression inserted
6
- * as last argument, using `init` for the first expression.
3
+ * Similar to {@link threadFirst}. A dataflow operator to improve the legibility
4
+ * of long (or deeply nested) call expressions. Takes an `init` value and a
5
+ * number of functions and/or function tuples, consisting of: `[fn, ...args]`.
6
+ * Executes each function (or tuple) with the return value of the previous
7
+ * step/function inserted as **last** argument, using `init` as the first
8
+ * expression. Returns result of last function/step given.
9
+ *
10
+ * @remarks
11
+ * This operator allows the code to be read more easily in the order of
12
+ * execution (same as the `->>` operator/macro in Clojure).
7
13
  *
8
14
  * @example
9
15
  * ```ts
@@ -11,18 +17,21 @@ import type { FnAny } from "@thi.ng/api";
11
17
  * const sub = (a, b) => a - b;
12
18
  * const div = (a, b) => a / b;
13
19
  *
20
+ * // without operator: 20 / (10 - (-5))
21
+ * console.log(div(20, sub(10, neg(5))));
22
+ * // 1.3333333333333333
23
+ *
24
+ * // rewritten using operator:
14
25
  * threadLast(
15
26
  * 5,
16
27
  * neg, // -5
17
- * [sub, 10], // 20 - (-5) = 25
18
- * [div, 10] // 10 / 25 = 0.4
28
+ * [sub, 10], // 10 - (-5)
29
+ * [div, 20], // 20 / (10 - (-5))
30
+ * console.log
19
31
  * );
20
- *
21
- * // 0.4
32
+ * // 1.3333333333333333
22
33
  * ```
23
34
  *
24
- * {@link threadFirst}
25
- *
26
35
  * @param init - start value
27
36
  * @param fns - functions / S-expressions
28
37
  */
package/thread-last.js CHANGED
@@ -1,8 +1,14 @@
1
1
  /**
2
- * Takes an `init` value and a number of functions and/or function
3
- * tuples, consisting of: `[fn, ...args]`. Executes each function
4
- * (or tuple) with the return value of the previous expression inserted
5
- * as last argument, using `init` for the first expression.
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).
6
12
  *
7
13
  * @example
8
14
  * ```ts
@@ -10,18 +16,21 @@
10
16
  * const sub = (a, b) => a - b;
11
17
  * const div = (a, b) => a / b;
12
18
  *
19
+ * // without operator: 20 / (10 - (-5))
20
+ * console.log(div(20, sub(10, neg(5))));
21
+ * // 1.3333333333333333
22
+ *
23
+ * // rewritten using operator:
13
24
  * threadLast(
14
25
  * 5,
15
26
  * neg, // -5
16
- * [sub, 10], // 20 - (-5) = 25
17
- * [div, 10] // 10 / 25 = 0.4
27
+ * [sub, 10], // 10 - (-5)
28
+ * [div, 20], // 20 / (10 - (-5))
29
+ * console.log
18
30
  * );
19
- *
20
- * // 0.4
31
+ * // 1.3333333333333333
21
32
  * ```
22
33
  *
23
- * {@link threadFirst}
24
- *
25
34
  * @param init - start value
26
35
  * @param fns - functions / S-expressions
27
36
  */