@nlozgachev/pipelined 0.18.0 → 0.19.0
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/README.md +17 -35
- package/dist/{chunk-5HMYR4XB.mjs → chunk-NRF2FVPZ.mjs} +1 -2
- package/dist/composition.js +1 -2
- package/dist/composition.mjs +1 -1
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,43 +61,25 @@ Everyday utilities for built-in JS types.
|
|
|
61
61
|
## Example
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
import {
|
|
64
|
+
import { Maybe, Result } from "@nlozgachev/pipelined/core";
|
|
65
65
|
import { pipe } from "@nlozgachev/pipelined/composition";
|
|
66
66
|
|
|
67
|
-
//
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
String,
|
|
84
|
-
),
|
|
85
|
-
TaskResult.pollUntil({
|
|
86
|
-
when: (job) => job.status === "done",
|
|
87
|
-
delay: (n) => n * 500, // 500 ms, 1 s, 1.5 s, ...
|
|
88
|
-
}),
|
|
89
|
-
TaskResult.map((job) => job.result),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// Compose the two — nothing runs until the final call
|
|
93
|
-
const message = await pipe(
|
|
94
|
-
getUser("abc"),
|
|
95
|
-
TaskResult.chain((user) => waitForExport(user.exportId)),
|
|
96
|
-
TaskResult.match({
|
|
97
|
-
ok: (r) => `Export ready: ${r.url}`,
|
|
98
|
-
err: (e) => `Failed: ${e}`,
|
|
99
|
-
}),
|
|
100
|
-
)();
|
|
67
|
+
// Chain nullable lookups without nested null checks
|
|
68
|
+
const city = pipe(
|
|
69
|
+
getUser(userId), // User | null
|
|
70
|
+
Maybe.fromNullable, // Maybe<User>
|
|
71
|
+
Maybe.chain((u) => Maybe.fromNullable(u.address)), // Maybe<Address>
|
|
72
|
+
Maybe.chain((a) => Maybe.fromNullable(a.city)), // Maybe<string>
|
|
73
|
+
Maybe.map((c) => c.toUpperCase()), // Maybe<string>
|
|
74
|
+
Maybe.getOrElse("UNKNOWN"), // string
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Parse input and look up a record — both steps can fail
|
|
78
|
+
const record = pipe(
|
|
79
|
+
parseId(rawInput), // Result<ParseError, number>
|
|
80
|
+
Result.chain((id) => db.find(id)), // Result<ParseError | NotFoundError, Record>
|
|
81
|
+
Result.map((r) => r.name), // Result<ParseError | NotFoundError, string>
|
|
82
|
+
);
|
|
101
83
|
```
|
|
102
84
|
|
|
103
85
|
## Documentation
|
|
@@ -166,8 +166,7 @@ var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
|
166
166
|
|
|
167
167
|
// src/Composition/pipe.ts
|
|
168
168
|
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
|
|
169
|
-
|
|
170
|
-
switch (len) {
|
|
169
|
+
switch (arguments.length) {
|
|
171
170
|
case 1:
|
|
172
171
|
return a;
|
|
173
172
|
case 2:
|
package/dist/composition.js
CHANGED
|
@@ -218,8 +218,7 @@ var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
|
218
218
|
|
|
219
219
|
// src/Composition/pipe.ts
|
|
220
220
|
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
|
|
221
|
-
|
|
222
|
-
switch (len) {
|
|
221
|
+
switch (arguments.length) {
|
|
223
222
|
case 1:
|
|
224
223
|
return a;
|
|
225
224
|
case 2:
|
package/dist/composition.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -245,8 +245,7 @@ var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
|
245
245
|
|
|
246
246
|
// src/Composition/pipe.ts
|
|
247
247
|
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
|
|
248
|
-
|
|
249
|
-
switch (len) {
|
|
248
|
+
switch (arguments.length) {
|
|
250
249
|
case 1:
|
|
251
250
|
return a;
|
|
252
251
|
case 2:
|
package/dist/index.mjs
CHANGED