@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 CHANGED
@@ -61,43 +61,25 @@ Everyday utilities for built-in JS types.
61
61
  ## Example
62
62
 
63
63
  ```ts
64
- import { TaskResult } from "@nlozgachev/pipelined/core";
64
+ import { Maybe, Result } from "@nlozgachev/pipelined/core";
65
65
  import { pipe } from "@nlozgachev/pipelined/composition";
66
66
 
67
- // Typed errors. Lazy. Composable.
68
- const getUser = (id: string): TaskResult<string, User> =>
69
- pipe(
70
- TaskResult.tryCatch(
71
- () => fetch(`/users/${id}`).then((r) => r.json() as Promise<User>),
72
- (e) => `fetch failed: ${e}`,
73
- ),
74
- TaskResult.timeout(5_000, () => "request timed out"),
75
- TaskResult.retry({ attempts: 3, backoff: (n) => n * 1_000 }),
76
- );
77
-
78
- // Poll until a background job finishes — stop immediately on failure
79
- const waitForExport = (jobId: string): TaskResult<string, ExportResult> =>
80
- pipe(
81
- TaskResult.tryCatch(
82
- () => fetch(`/exports/${jobId}`).then((r) => r.json() as Promise<Job>),
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
- const len = arguments.length;
170
- switch (len) {
169
+ switch (arguments.length) {
171
170
  case 1:
172
171
  return a;
173
172
  case 2:
@@ -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
- const len = arguments.length;
222
- switch (len) {
221
+ switch (arguments.length) {
223
222
  case 1:
224
223
  return a;
225
224
  case 2:
@@ -26,7 +26,7 @@ import {
26
26
  uncurry,
27
27
  uncurry3,
28
28
  uncurry4
29
- } from "./chunk-5HMYR4XB.mjs";
29
+ } from "./chunk-NRF2FVPZ.mjs";
30
30
  export {
31
31
  and,
32
32
  compose,
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
- const len = arguments.length;
249
- switch (len) {
248
+ switch (arguments.length) {
250
249
  case 1:
251
250
  return a;
252
251
  case 2:
package/dist/index.mjs CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  uncurry,
27
27
  uncurry3,
28
28
  uncurry4
29
- } from "./chunk-5HMYR4XB.mjs";
29
+ } from "./chunk-NRF2FVPZ.mjs";
30
30
  import {
31
31
  Lens,
32
32
  Logged,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipelined",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Simple functional programming toolkit for TypeScript",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://pipelined.lozgachev.dev",