@resultsafe/core-fp-result 0.1.8 → 0.1.10

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.
Files changed (69) hide show
  1. package/README.md +305 -302
  2. package/README.ru.md +304 -302
  3. package/docs/api/README.md +52 -7
  4. package/docs/api/{constructors → functions}/Err.md +9 -11
  5. package/docs/api/{constructors → functions}/Ok.md +9 -11
  6. package/docs/api/{methods → functions}/andThen.md +9 -11
  7. package/docs/api/{methods/err.md → functions/err-1.md} +9 -11
  8. package/docs/api/{methods → functions}/expect.md +10 -12
  9. package/docs/api/{methods → functions}/expectErr.md +10 -12
  10. package/docs/api/{methods → functions}/flatten.md +9 -11
  11. package/docs/api/{methods → functions}/inspect.md +9 -11
  12. package/docs/api/{methods → functions}/inspectErr.md +9 -11
  13. package/docs/api/{guards → functions}/isErr.md +9 -11
  14. package/docs/api/{guards → functions}/isErrAnd.md +9 -11
  15. package/docs/api/{guards → functions}/isOk.md +9 -11
  16. package/docs/api/{guards → functions}/isOkAnd.md +9 -11
  17. package/docs/api/{refiners → functions}/isTypedVariant.md +11 -13
  18. package/docs/api/{refiners → functions}/isTypedVariantOf.md +11 -13
  19. package/docs/api/{methods → functions}/map.md +9 -11
  20. package/docs/api/{methods → functions}/mapErr.md +9 -11
  21. package/docs/api/{methods → functions}/match.md +9 -11
  22. package/docs/api/{refiners → functions}/matchVariant.md +9 -11
  23. package/docs/api/{refiners → functions}/matchVariantStrict.md +10 -12
  24. package/docs/api/{methods/ok.md → functions/ok-1.md} +9 -11
  25. package/docs/api/{methods → functions}/orElse.md +9 -11
  26. package/docs/api/{refiners → functions}/refineAsyncResult.md +17 -19
  27. package/docs/api/{refiners → functions}/refineAsyncResultU.md +9 -11
  28. package/docs/api/{refiners → functions}/refineResult.md +17 -19
  29. package/docs/api/{refiners → functions}/refineResultU.md +9 -11
  30. package/docs/api/{refiners → functions}/refineVariantMap.md +9 -11
  31. package/docs/api/{methods → functions}/tap.md +9 -11
  32. package/docs/api/{methods → functions}/tapErr.md +9 -11
  33. package/docs/api/{methods → functions}/transpose.md +9 -11
  34. package/docs/api/{methods → functions}/unwrap.md +10 -12
  35. package/docs/api/{methods → functions}/unwrapErr.md +10 -12
  36. package/docs/api/{methods → functions}/unwrapOr.md +9 -11
  37. package/docs/api/{methods → functions}/unwrapOrElse.md +9 -11
  38. package/docs/api/type-aliases/Handler.md +1 -1
  39. package/docs/api/type-aliases/MatchBuilder.md +1 -1
  40. package/docs/api/type-aliases/Matcher.md +1 -1
  41. package/docs/api/type-aliases/SyncRefinedResult.md +1 -1
  42. package/docs/api/type-aliases/SyncRefinedResultUnion.md +1 -1
  43. package/docs/api/type-aliases/SyncValidatorMap.md +1 -1
  44. package/docs/api/type-aliases/UniversalAsyncRefinedResult.md +1 -1
  45. package/docs/api/type-aliases/UniversalRefinedResult.md +1 -1
  46. package/docs/api/type-aliases/VariantOf.md +1 -1
  47. package/docs/examples/auth/index.md +1 -1
  48. package/docs/examples/auth/token.md +1 -1
  49. package/docs/examples/connection/connect.md +1 -1
  50. package/docs/examples/connection/index.md +1 -1
  51. package/docs/examples/connection/reconnect.md +1 -1
  52. package/docs/examples/errors/index.md +1 -1
  53. package/docs/examples/errors/retry.md +1 -1
  54. package/docs/examples/index.md +1 -1
  55. package/docs/examples/streaming/index.md +1 -1
  56. package/docs/examples/streaming/text.md +1 -1
  57. package/docs/meta/AI-AGENT-RULES.md +1 -1
  58. package/docs/meta/CONTEXT.md +1 -1
  59. package/docs/meta/MANIFEST.md +1 -1
  60. package/docs/meta/registry/COUNTERS.md +1 -1
  61. package/docs/meta/registry/ENTITIES.md +1 -1
  62. package/package.json +1 -1
  63. package/docs/api/constructors/index.md +0 -7
  64. package/docs/api/guards/index.md +0 -9
  65. package/docs/api/index.md +0 -9
  66. package/docs/api/methods/index.md +0 -24
  67. package/docs/api/modules.md +0 -10
  68. package/docs/api/refiners/index.md +0 -14
  69. package/docs/api/type-aliases/index.md +0 -14
package/README.md CHANGED
@@ -1,302 +1,305 @@
1
- # @resultsafe/core-fp-result
2
- <a id="top"></a>
3
-
4
- ![ResultSafe Logo](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/assets/logo.svg)
5
-
6
- [![npm version](https://img.shields.io/npm/v/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
7
- [![npm downloads](https://img.shields.io/npm/dm/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
8
- [![license](https://img.shields.io/npm/l/@resultsafe/core-fp-result.svg)](./LICENSE)
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6.svg)](https://www.typescriptlang.org/)
10
- [![docs](https://img.shields.io/badge/docs-api-informational.svg)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
11
- [![build status](https://img.shields.io/badge/build-local%20verified-success.svg)](./package.json)
12
- [![monorepo](https://img.shields.io/badge/monorepo-resultsafe%2Fmonorepo-0A0A0A.svg)](https://github.com/resultsafe/monorepo)
13
-
14
- A Rust-inspired Result package for explicit, composable, and type-friendly APIs in TypeScript and JavaScript.
15
-
16
- **Language:** English | [Русский](https://github.com/resultsafe/monorepo/blob/main/packages/core/fp/result/README.ru.md)
17
-
18
- **Documentation:** [API index](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md) · [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
19
-
20
- ---
21
- ## Contents
22
-
23
- - [Why this package](#why-this-package)
24
- - [Monorepo context](#monorepo-context)
25
- - [Key features](#key-features)
26
- - [Package](#package)
27
- - [Installation](#installation)
28
- - [Quick start](#quick-start)
29
- - [Core API overview](#core-api-overview)
30
- - [Build and distribution formats](#build-and-distribution-formats)
31
- - [Monorepo and package structure](#monorepo-and-package-structure)
32
- - [When to use this project](#when-to-use-this-project)
33
- - [Documentation links](#documentation-links)
34
- - [License](#license)
35
-
36
- ---
37
-
38
- ## Why this package
39
-
40
- `@resultsafe/core-fp-result` provides explicit success/error flows instead of hidden control paths and exception-first branching.
41
-
42
- Its core package, [`@resultsafe/core-fp-result`](https://www.npmjs.com/package/@resultsafe/core-fp-result), provides a Rust-inspired `Result` API for TypeScript and JavaScript with:
43
-
44
- - explicit `Ok` / `Err`
45
- - predictable functional composition
46
- - safe branching through guards and matching
47
- - disciplined extraction APIs
48
- - advanced refinement utilities for typed variants and strict matching
49
-
50
- The goal is not to imitate Rust mechanically, but to bring the same clarity of intent to Node.js libraries: explicit values, predictable branching, and APIs organized for long-term maintenance.
51
-
52
- ---
53
-
54
- ## Monorepo context
55
-
56
- `@resultsafe/core-fp-result` is the TypeScript/JavaScript package inside the multilingual `resultsafe/monorepo`.
57
-
58
- The monorepo applies shared Rust-inspired design concepts across language-specific packages. TypeScript/JavaScript is the current production package track, while Python is planned as a separate package track with the same conceptual model.
59
-
60
- ---
61
-
62
- ## Key features
63
-
64
- - Rust-inspired `Result` model for TypeScript and JavaScript.
65
- - Explicit constructors via `Ok` and `Err`.
66
- - Composable transformations with APIs such as `map`, `mapErr`, `andThen`, and `orElse`.
67
- - Safe branching through guards like `isOk`, `isErr`, `isOkAnd`, `isErrAnd`, and matching helpers.
68
- - Controlled extraction with `unwrap`, `unwrapOr`, `unwrapErr`, `expect`, and `expectErr`.
69
- - Advanced refinement layer for typed variants, strict matching, and result narrowing.
70
- - Coherent module structure instead of a flat utility dump.
71
- - Type output for TypeScript users for better DX and safer integrations.
72
- - Flexible distribution formats with Types, ESM, CJS, and UMD builds.
73
-
74
- ---
75
-
76
- ## Package
77
-
78
- ### `@resultsafe/core-fp-result`
79
-
80
- A focused Result library for explicit error handling and FP-style composition.
81
-
82
- It is designed for developers who want:
83
-
84
- - clear success/error modeling
85
- - predictable transformations
86
- - explicit branching and extraction
87
- - better readability in error-heavy flows
88
- - a structured Rust-inspired API surface in TypeScript/JavaScript
89
-
90
- ---
91
-
92
- ## Installation
93
-
94
- ### Package
95
-
96
- ```bash
97
- pnpm add @resultsafe/core-fp-result
98
-
99
- # Alternative
100
- npm install @resultsafe/core-fp-result
101
- ```
102
-
103
- ### Monorepo
104
-
105
- ```bash
106
- pnpm install
107
- ```
108
-
109
- ---
110
-
111
- ## Quick start
112
-
113
- A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
114
-
115
- ```ts
116
- import {
117
- Ok,
118
- map,
119
- unwrapOr,
120
- } from "@resultsafe/core-fp-result";
121
-
122
- const initial = Ok(21);
123
- const doubled = map(initial, (value) => value * 2);
124
- const finalValue = unwrapOr(doubled, 0);
125
-
126
- console.log(finalValue); // 42
127
- ```
128
-
129
- ### Basic `Ok` / `Err` example
130
-
131
- ```ts
132
- import { Ok, Err, match } from "@resultsafe/core-fp-result";
133
-
134
- const parsePort = (input: string) => {
135
- const port = Number(input);
136
- return Number.isInteger(port) && port > 0
137
- ? Ok(port)
138
- : Err("Invalid port");
139
- };
140
-
141
- const result = parsePort("3000");
142
- const message = match(result, (value) => `Port: ${value}`, (error) => `Error: ${error}`);
143
-
144
- console.log(message);
145
- ```
146
-
147
- ---
148
-
149
- <!-- AI-AGENT: Each function has 3 links: Source (GitHub UI), Raw (direct code), Code (new UI) -->
150
- <!-- Raw links are best for automated code analysis and parsing -->
151
-
152
- ## Core API overview
153
-
154
- ### Core Types
155
-
156
- - [`Result<T, E>`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Result.ts) — Success/failure container [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Result.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/core/Result.ts "Open in Code view")
157
- - [`Option<T>`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Option.ts) — Optional value container [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Option.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/core/Option.ts "Open in Code view")
158
-
159
- ### Type Helpers
160
-
161
- - [`VariantConfig`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) — Variant configuration [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts "Open in Code view")
162
- - [`PayloadKeys<T>`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts) — Extract payload keys [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts "Open in Code view")
163
- - [`ValidatorFn<T>`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) — Sync validator function [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts "Open in Code view")
164
- - [`AsyncValidatorFn`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) — Async validator function [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts "Open in Code view")
165
-
166
- ### Constructors
167
-
168
- - [`Ok`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Ok.ts) — Create success result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Ok.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/constructors/Ok.ts "Open in Code view")
169
- - [`Err`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Err.ts) — Create error result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Err.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/constructors/Err.ts "Open in Code view")
170
-
171
- ### Guards
172
-
173
- - [`isOk`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOk.ts) — Check if success [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOk.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/guards/isOk.ts "Open in Code view")
174
- - [`isErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErr.ts) — Check if error [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/guards/isErr.ts "Open in Code view")
175
- - [`isOkAnd`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOkAnd.ts) — Check success with predicate [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOkAnd.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOkAnd.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/guards/isOkAnd.ts "Open in Code view")
176
- - [`isErrAnd`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErrAnd.ts) — Check error with predicate [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErrAnd.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErrAnd.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/guards/isErrAnd.ts "Open in Code view")
177
-
178
- ### Methods
179
-
180
- #### Transformation
181
-
182
- - [`map`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/map.ts) — Transform success value [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/map.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/map.ts "Open in Code view")
183
- - [`mapErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/mapErr.ts) — Transform error value [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/mapErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/mapErr.ts "Open in Code view")
184
-
185
- #### Chaining
186
-
187
- - [`andThen`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/andThen.ts) — Chain computations returning Result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/andThen.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/andThen.ts "Open in Code view")
188
- - [`orElse`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/orElse.ts) — Recover from error [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/orElse.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/orElse.ts "Open in Code view")
189
-
190
- #### Extraction
191
-
192
- - [`unwrap`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrap.ts) — Extract value or throw [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrap.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/unwrap.ts "Open in Code view")
193
- - [`unwrapOr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOr.ts) — Extract value or default [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/unwrapOr.ts "Open in Code view")
194
- - [`unwrapOrElse`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOrElse.ts) — Extract value or compute default [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOrElse.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOrElse.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/unwrapOrElse.ts "Open in Code view")
195
- - [`unwrapErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapErr.ts) — Extract error or throw [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/unwrapErr.ts "Open in Code view")
196
- - [`expect`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expect.ts) — Extract value or throw with message [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expect.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/expect.ts "Open in Code view")
197
- - [`expectErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expectErr.ts) — Extract error or throw with message [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expectErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expectErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/expectErr.ts "Open in Code view")
198
-
199
- #### Side Effects
200
-
201
- - [`tap`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tap.ts) — Side effect on success [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tap.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/tap.ts "Open in Code view")
202
- - [`tapErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tapErr.ts) — Side effect on error [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tapErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/tapErr.ts "Open in Code view")
203
- - [`inspect`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/inspect.ts) — Debug on success [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/inspect.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspect.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/inspect.ts "Open in Code view")
204
- - [`inspectErr`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/inspectErr.ts) — Debug on error [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/inspectErr.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspectErr.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/inspectErr.ts "Open in Code view")
205
-
206
- #### Advanced
207
-
208
- - [`match`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/match.ts) — Pattern matching [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/match.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/match.ts "Open in Code view")
209
- - [`flatten`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/flatten.ts) — Flatten nested Result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/flatten.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/flatten.ts "Open in Code view")
210
- - [`transpose`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/transpose.ts) — Result<Option> → Option<Result> [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/transpose.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/transpose.ts "Open in Code view")
211
- - [`ok`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/ok.ts) — Convert to Option (success) [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/ok.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/ok.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/ok.ts "Open in Code view")
212
- - [`err`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/err.ts) — Convert to Option (error) [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/err.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/err.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/methods/err.ts "Open in Code view")
213
-
214
- ### Refiners
215
-
216
- - [`isTypedVariant`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) — Type guard for variant [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariant.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/isTypedVariant.ts "Open in Code view")
217
- - [`isTypedVariantOf`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts) — Type guard with variant map [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts "Open in Code view")
218
- - [`matchVariant`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariant.ts) — Match variant with handlers [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariant.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/matchVariant.ts "Open in Code view")
219
- - [`matchVariantStrict`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) — Strict variant matching [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts "Open in Code view")
220
- - [`refineAsyncResult`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) — Async result refinement [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts "Open in Code view")
221
- - [`refineAsyncResultU`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts) — Async refinement (uncurried) [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts "Open in Code view")
222
- - [`refineResult`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResult.ts) — Synchronous result refinement [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResult.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/refineResult.ts "Open in Code view")
223
- - [`refineResultU`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResultU.ts) — Synchronous refinement (uncurried) [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResultU.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResultU.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/refineResultU.ts "Open in Code view")
224
- - [`refineVariantMap`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineVariantMap.ts) — Refine variant map [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineVariantMap.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineVariantMap.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/refineVariantMap.ts "Open in Code view")
225
-
226
- ### Type aliases
227
-
228
- - [`Handler`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/Handler.ts) — Match handler type [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/Handler.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Handler.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/Handler.ts "Open in Code view")
229
- - [`MatchBuilder`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts) — Match builder type [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts "Open in Code view")
230
- - [`Matcher`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/Matcher.ts) — Matcher function type [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/Matcher.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Matcher.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/Matcher.ts "Open in Code view")
231
- - [`SyncRefinedResult`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts) — Synchronous refined result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts "Open in Code view")
232
- - [`SyncRefinedResultUnion`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts) — Union of refined results [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts "Open in Code view")
233
- - [`SyncValidatorMap`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts) — Validator map type [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts "Open in Code view")
234
- - [`UniversalAsyncRefinedResult`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts) — Async refined result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts "Open in Code view")
235
- - [`UniversalRefinedResult`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts) — Universal refined result [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts "Open in Code view")
236
- - [`VariantOf`](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/VariantOf.ts) — Variant type helper [📄](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/types/VariantOf.ts "View on GitHub") · [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/VariantOf.ts "View raw code") · [💻](https://github.com/Livooon/resultsafe/code/main/packages/core/fp/result/src/refiners/types/VariantOf.ts "Open in Code view")
237
-
238
- ---
239
-
240
- ## Build and distribution formats
241
-
242
- - Types: `build:types`
243
- - ESM: `build:esm`
244
- - CJS: `build:cjs`
245
- - UMD: `build:umd`
246
-
247
- This package ships typed declarations and multiple runtime module formats for broad compatibility.
248
-
249
- ---
250
-
251
- ## Monorepo and package structure
252
-
253
- ```txt
254
- src/
255
- constructors/
256
- guards/
257
- methods/
258
- refiners/
259
- types/
260
- utils/
261
- internal/
262
- index.ts
263
- ```
264
-
265
- ---
266
-
267
- ## When to use this project
268
-
269
- Use this project when you want:
270
-
271
- - explicit success/error modeling
272
- - predictable FP-style composition
273
- - visible control flow
274
- - stronger type-guided result handling in TypeScript
275
- - advanced refinement tools for typed variants and strict result matching
276
-
277
- ---
278
-
279
- ## Documentation links
280
-
281
- - [API entry (README)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
282
- - [API entry (index)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/index.md)
283
- - [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
284
- - [Constructors module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md)
285
- - [Guards module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md)
286
- - [Methods module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md)
287
- - [Refiners module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
288
- - [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
289
-
290
- ---
291
- Back to top: [@resultsafe/core-fp-result](#top)
292
-
293
- ---
294
- ## Author
295
-
296
- Denis Savasteev
297
-
298
- ---
299
-
300
- ## License
301
-
302
- [MIT](./LICENSE)
1
+ # @resultsafe/core-fp-result
2
+
3
+ <a id="top"></a>
4
+
5
+ > ✅ **Version 0.1.9** | UTF-8 encoded documentation | AI-optimized for developer collaboration
6
+
7
+ ![ResultSafe Logo](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/docs/assets/logo.svg)
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
10
+ [![npm downloads](https://img.shields.io/npm/dm/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
11
+ [![license](https://img.shields.io/npm/l/@resultsafe/core-fp-result.svg)](./LICENSE)
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6.svg)](https://www.typescriptlang.org/)
13
+ [![docs](https://img.shields.io/badge/docs-api-informational.svg)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
14
+ [![build status](https://img.shields.io/badge/build-local%20verified-success.svg)](./package.json)
15
+ [![monorepo](https://img.shields.io/badge/monorepo-resultsafe%2Fmonorepo-0A0A0A.svg)](https://github.com/Livooon/resultsafe)
16
+
17
+ A Rust-inspired Result package for explicit, composable, and type-friendly APIs in TypeScript and JavaScript.
18
+
19
+ **Language:** English | [Русский](https://github.com/resultsafe/monorepo/blob/main/packages/core/fp/result/README.ru.md)
20
+
21
+ **Documentation:** [API index](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md) · [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
22
+
23
+ ---
24
+ ## Contents
25
+
26
+ - [Why this package](#why-this-package)
27
+ - [Monorepo context](#monorepo-context)
28
+ - [Key features](#key-features)
29
+ - [Package](#package)
30
+ - [Installation](#installation)
31
+ - [Quick start](#quick-start)
32
+ - [Core API overview](#core-api-overview)
33
+ - [Build and distribution formats](#build-and-distribution-formats)
34
+ - [Monorepo and package structure](#monorepo-and-package-structure)
35
+ - [When to use this project](#when-to-use-this-project)
36
+ - [Documentation links](#documentation-links)
37
+ - [License](#license)
38
+
39
+ ---
40
+
41
+ ## Why this package
42
+
43
+ `@resultsafe/core-fp-result` provides explicit success/error flows instead of hidden control paths and exception-first branching.
44
+
45
+ Its core package, [`@resultsafe/core-fp-result`](https://www.npmjs.com/package/@resultsafe/core-fp-result), provides a Rust-inspired `Result` API for TypeScript and JavaScript with:
46
+
47
+ - explicit `Ok` / `Err`
48
+ - predictable functional composition
49
+ - safe branching through guards and matching
50
+ - disciplined extraction APIs
51
+ - advanced refinement utilities for typed variants and strict matching
52
+
53
+ The goal is not to imitate Rust mechanically, but to bring the same clarity of intent to Node.js libraries: explicit values, predictable branching, and APIs organized for long-term maintenance.
54
+
55
+ ---
56
+
57
+ ## Monorepo context
58
+
59
+ `@resultsafe/core-fp-result` is the TypeScript/JavaScript package inside the multilingual `resultsafe/monorepo`.
60
+
61
+ The monorepo applies shared Rust-inspired design concepts across language-specific packages. TypeScript/JavaScript is the current production package track, while Python is planned as a separate package track with the same conceptual model.
62
+
63
+ ---
64
+
65
+ ## Key features
66
+
67
+ - Rust-inspired `Result` model for TypeScript and JavaScript.
68
+ - Explicit constructors via `Ok` and `Err`.
69
+ - Composable transformations with APIs such as `map`, `mapErr`, `andThen`, and `orElse`.
70
+ - Safe branching through guards like `isOk`, `isErr`, `isOkAnd`, `isErrAnd`, and matching helpers.
71
+ - Controlled extraction with `unwrap`, `unwrapOr`, `unwrapErr`, `expect`, and `expectErr`.
72
+ - Advanced refinement layer for typed variants, strict matching, and result narrowing.
73
+ - Coherent module structure instead of a flat utility dump.
74
+ - Type output for TypeScript users for better DX and safer integrations.
75
+ - Flexible distribution formats with Types, ESM, CJS, and UMD builds.
76
+
77
+ ---
78
+
79
+ ## Package
80
+
81
+ ### `@resultsafe/core-fp-result`
82
+
83
+ A focused Result library for explicit error handling and FP-style composition.
84
+
85
+ It is designed for developers who want:
86
+
87
+ - clear success/error modeling
88
+ - predictable transformations
89
+ - explicit branching and extraction
90
+ - better readability in error-heavy flows
91
+ - a structured Rust-inspired API surface in TypeScript/JavaScript
92
+
93
+ ---
94
+
95
+ ## Installation
96
+
97
+ ### Package
98
+
99
+ ```bash
100
+ pnpm add @resultsafe/core-fp-result
101
+
102
+ # Alternative
103
+ npm install @resultsafe/core-fp-result
104
+ ```
105
+
106
+ ### Monorepo
107
+
108
+ ```bash
109
+ pnpm install
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Quick start
115
+
116
+ A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
117
+
118
+ ```ts
119
+ import {
120
+ Ok,
121
+ map,
122
+ unwrapOr,
123
+ } from "@resultsafe/core-fp-result";
124
+
125
+ const initial = Ok(21);
126
+ const doubled = map(initial, (value) => value * 2);
127
+ const finalValue = unwrapOr(doubled, 0);
128
+
129
+ console.log(finalValue); // 42
130
+ ```
131
+
132
+ ### Basic `Ok` / `Err` example
133
+
134
+ ```ts
135
+ import { Ok, Err, match } from "@resultsafe/core-fp-result";
136
+
137
+ const parsePort = (input: string) => {
138
+ const port = Number(input);
139
+ return Number.isInteger(port) && port > 0
140
+ ? Ok(port)
141
+ : Err("Invalid port");
142
+ };
143
+
144
+ const result = parsePort("3000");
145
+ const message = match(result, (value) => `Port: ${value}`, (error) => `Error: ${error}`);
146
+
147
+ console.log(message);
148
+ ```
149
+
150
+ ---
151
+
152
+ <!-- AI-AGENT: Each function has 3 links: Source (GitHub UI), Raw (direct code), Code (new UI) -->
153
+ <!-- Raw links are best for automated code analysis and parsing -->
154
+
155
+ ## Core API overview
156
+
157
+ ### Core Types
158
+
159
+ - [`Result<T, E>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts) — Success/failure container [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts "View raw code")
160
+ - [`Option<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts) — Optional value container [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts "View raw code")
161
+
162
+ ### Type Helpers
163
+
164
+ - [`VariantConfig`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) — Variant configuration [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts "View raw code")
165
+ - [`PayloadKeys<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts) — Extract payload keys [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts "View raw code")
166
+ - [`ValidatorFn<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) — Sync validator function [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts "View raw code")
167
+ - [`AsyncValidatorFn`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) — Async validator function [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts "View raw code")
168
+
169
+ ### Constructors
170
+
171
+ - [`Ok`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts) — Create success result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts "View raw code")
172
+ - [`Err`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts) — Create error result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts "View raw code")
173
+
174
+ ### Guards
175
+
176
+ - [`isOk`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts) — Check if success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts "View raw code")
177
+ - [`isErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts) — Check if error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts "View raw code")
178
+ - [`isOkAnd`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOkAnd.ts) — Check success with predicate [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOkAnd.ts "View raw code")
179
+ - [`isErrAnd`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErrAnd.ts) — Check error with predicate [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErrAnd.ts "View raw code")
180
+
181
+ ### Methods
182
+
183
+ #### Transformation
184
+
185
+ - [`map`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts) — Transform success value [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts "View raw code")
186
+ - [`mapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts) — Transform error value [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts "View raw code")
187
+
188
+ #### Chaining
189
+
190
+ - [`andThen`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts) — Chain computations returning Result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts "View raw code")
191
+ - [`orElse`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts) — Recover from error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts "View raw code")
192
+
193
+ #### Extraction
194
+
195
+ - [`unwrap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts) — Extract value or throw [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts "View raw code")
196
+ - [`unwrapOr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts) — Extract value or default [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts "View raw code")
197
+ - [`unwrapOrElse`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOrElse.ts) — Extract value or compute default [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOrElse.ts "View raw code")
198
+ - [`unwrapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapErr.ts) — Extract error or throw [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapErr.ts "View raw code")
199
+ - [`expect`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts) — Extract value or throw with message [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts "View raw code")
200
+ - [`expectErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expectErr.ts) — Extract error or throw with message [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expectErr.ts "View raw code")
201
+
202
+ #### Side Effects
203
+
204
+ - [`tap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts) — Side effect on success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts "View raw code")
205
+ - [`tapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts) — Side effect on error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts "View raw code")
206
+ - [`inspect`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspect.ts) — Debug on success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspect.ts "View raw code")
207
+ - [`inspectErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspectErr.ts) — Debug on error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspectErr.ts "View raw code")
208
+
209
+ #### Advanced
210
+
211
+ - [`match`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts) — Pattern matching [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts "View raw code")
212
+ - [`flatten`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts) — Flatten nested Result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts "View raw code")
213
+ - [`transpose`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts) — Result<Option> → Option<Result> [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts "View raw code")
214
+ - [`ok`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/ok.ts) — Convert to Option (success) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/ok.ts "View raw code")
215
+ - [`err`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/err.ts) — Convert to Option (error) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/err.ts "View raw code")
216
+
217
+ ### Refiners
218
+
219
+ - [`isTypedVariant`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) — Type guard for variant [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts "View raw code")
220
+ - [`isTypedVariantOf`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts) — Type guard with variant map [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts "View raw code")
221
+ - [`matchVariant`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts) — Match variant with handlers [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts "View raw code")
222
+ - [`matchVariantStrict`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) — Strict variant matching [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts "View raw code")
223
+ - [`refineAsyncResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) — Async result refinement [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts "View raw code")
224
+ - [`refineAsyncResultU`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts) — Async refinement (uncurried) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts "View raw code")
225
+ - [`refineResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts) — Synchronous result refinement [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts "View raw code")
226
+ - [`refineResultU`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResultU.ts) — Synchronous refinement (uncurried) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResultU.ts "View raw code")
227
+ - [`refineVariantMap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineVariantMap.ts) — Refine variant map [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineVariantMap.ts "View raw code")
228
+
229
+ ### Type aliases
230
+
231
+ - [`Handler`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Handler.ts) — Match handler type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Handler.ts "View raw code")
232
+ - [`MatchBuilder`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts) — Match builder type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts "View raw code")
233
+ - [`Matcher`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Matcher.ts) — Matcher function type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Matcher.ts "View raw code")
234
+ - [`SyncRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts) — Synchronous refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts "View raw code")
235
+ - [`SyncRefinedResultUnion`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts) — Union of refined results [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts "View raw code")
236
+ - [`SyncValidatorMap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts) — Validator map type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts "View raw code")
237
+ - [`UniversalAsyncRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts) — Async refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts "View raw code")
238
+ - [`UniversalRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts) — Universal refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts "View raw code")
239
+ - [`VariantOf`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/VariantOf.ts) — Variant type helper [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/VariantOf.ts "View raw code")
240
+
241
+ ---
242
+
243
+ ## Build and distribution formats
244
+
245
+ - Types: `build:types`
246
+ - ESM: `build:esm`
247
+ - CJS: `build:cjs`
248
+ - UMD: `build:umd`
249
+
250
+ This package ships typed declarations and multiple runtime module formats for broad compatibility.
251
+
252
+ ---
253
+
254
+ ## Monorepo and package structure
255
+
256
+ ```txt
257
+ src/
258
+ constructors/
259
+ guards/
260
+ methods/
261
+ refiners/
262
+ types/
263
+ utils/
264
+ internal/
265
+ index.ts
266
+ ```
267
+
268
+ ---
269
+
270
+ ## When to use this project
271
+
272
+ Use this project when you want:
273
+
274
+ - explicit success/error modeling
275
+ - predictable FP-style composition
276
+ - visible control flow
277
+ - stronger type-guided result handling in TypeScript
278
+ - advanced refinement tools for typed variants and strict result matching
279
+
280
+ ---
281
+
282
+ ## Documentation links
283
+
284
+ - [API entry (README)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
285
+ - [API entry (index)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/index.md)
286
+ - [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
287
+ - [Constructors module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md)
288
+ - [Guards module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md)
289
+ - [Methods module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md)
290
+ - [Refiners module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
291
+ - [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
292
+
293
+ ---
294
+ Back to top: [@resultsafe/core-fp-result](#top)
295
+
296
+ ---
297
+ ## Author
298
+
299
+ Denis Savasteev
300
+
301
+ ---
302
+
303
+ ## License
304
+
305
+ [MIT](./LICENSE)