@thi.ng/compose 2.1.40 → 2.1.42
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 +1 -1
- package/README.md +14 -0
- package/package.json +2 -2
- package/thread-first.d.ts +19 -10
- package/thread-first.js +19 -10
- package/thread-last.d.ts +19 -10
- package/thread-last.js +19 -10
package/CHANGELOG.md
CHANGED
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,19 @@ 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/poly-subdiv.jpg" width="240"/> | Animated, iterative polygon subdivisions & visualization | [Demo](https://demo.thi.ng/umbrella/poly-subdiv/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-subdiv) |
|
|
70
|
+
| <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) |
|
|
71
|
+
|
|
58
72
|
## API
|
|
59
73
|
|
|
60
74
|
[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.
|
|
3
|
+
"version": "2.1.42",
|
|
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": "
|
|
108
|
+
"gitHead": "d492ecb41df758db372a76449ea9b5bad47b25c4\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
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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,
|
|
18
|
-
* [div,
|
|
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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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,
|
|
17
|
-
* [div,
|
|
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
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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], //
|
|
18
|
-
* [div,
|
|
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
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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], //
|
|
17
|
-
* [div,
|
|
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
|
*/
|