@resultsafe/core-fp-result 0.1.10 → 0.2.1

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 (166) hide show
  1. package/README.md +355 -305
  2. package/cjs/constructors/Err.js.map +1 -1
  3. package/cjs/constructors/Ok.js.map +1 -1
  4. package/cjs/guards/isErr.js.map +1 -1
  5. package/cjs/guards/isErrAnd.js.map +1 -1
  6. package/cjs/guards/isOk.js.map +1 -1
  7. package/cjs/guards/isOkAnd.js.map +1 -1
  8. package/cjs/methods/andThen.js.map +1 -1
  9. package/cjs/methods/err.js.map +1 -1
  10. package/cjs/methods/expect.js.map +1 -1
  11. package/cjs/methods/expectErr.js.map +1 -1
  12. package/cjs/methods/flatten.js.map +1 -1
  13. package/cjs/methods/inspect.js.map +1 -1
  14. package/cjs/methods/inspectErr.js.map +1 -1
  15. package/cjs/methods/map.js.map +1 -1
  16. package/cjs/methods/mapErr.js.map +1 -1
  17. package/cjs/methods/match.js.map +1 -1
  18. package/cjs/methods/ok.js.map +1 -1
  19. package/cjs/methods/orElse.js.map +1 -1
  20. package/cjs/methods/tap.js.map +1 -1
  21. package/cjs/methods/tapErr.js.map +1 -1
  22. package/cjs/methods/transpose.js.map +1 -1
  23. package/cjs/methods/unwrap.js.map +1 -1
  24. package/cjs/methods/unwrapErr.js.map +1 -1
  25. package/cjs/methods/unwrapOr.js.map +1 -1
  26. package/cjs/methods/unwrapOrElse.js.map +1 -1
  27. package/cjs/refiners/isTypedVariant.js.map +1 -1
  28. package/cjs/refiners/isTypedVariantOf.js.map +1 -1
  29. package/cjs/refiners/matchVariant.js.map +1 -1
  30. package/cjs/refiners/matchVariantStrict.js.map +1 -1
  31. package/cjs/refiners/refineAsyncResult.js.map +1 -1
  32. package/cjs/refiners/refineAsyncResultU.js.map +1 -1
  33. package/cjs/refiners/refineResult.js.map +1 -1
  34. package/cjs/refiners/refineResultU.js.map +1 -1
  35. package/cjs/refiners/refineVariantMap.js.map +1 -1
  36. package/cjs/refiners/utils/getPayloadKeys.js.map +1 -1
  37. package/docs/assets/logo.svg +0 -0
  38. package/esm/constructors/Err.js.map +1 -1
  39. package/esm/constructors/Ok.js.map +1 -1
  40. package/esm/guards/isErr.js.map +1 -1
  41. package/esm/guards/isErrAnd.js.map +1 -1
  42. package/esm/guards/isOk.js.map +1 -1
  43. package/esm/guards/isOkAnd.js.map +1 -1
  44. package/esm/methods/andThen.js.map +1 -1
  45. package/esm/methods/err.js.map +1 -1
  46. package/esm/methods/expect.js.map +1 -1
  47. package/esm/methods/expectErr.js.map +1 -1
  48. package/esm/methods/flatten.js.map +1 -1
  49. package/esm/methods/inspect.js.map +1 -1
  50. package/esm/methods/inspectErr.js.map +1 -1
  51. package/esm/methods/map.js.map +1 -1
  52. package/esm/methods/mapErr.js.map +1 -1
  53. package/esm/methods/match.js.map +1 -1
  54. package/esm/methods/ok.js.map +1 -1
  55. package/esm/methods/orElse.js.map +1 -1
  56. package/esm/methods/tap.js.map +1 -1
  57. package/esm/methods/tapErr.js.map +1 -1
  58. package/esm/methods/transpose.js.map +1 -1
  59. package/esm/methods/unwrap.js.map +1 -1
  60. package/esm/methods/unwrapErr.js.map +1 -1
  61. package/esm/methods/unwrapOr.js.map +1 -1
  62. package/esm/methods/unwrapOrElse.js.map +1 -1
  63. package/esm/refiners/isTypedVariant.js.map +1 -1
  64. package/esm/refiners/isTypedVariantOf.js.map +1 -1
  65. package/esm/refiners/matchVariant.js.map +1 -1
  66. package/esm/refiners/matchVariantStrict.js.map +1 -1
  67. package/esm/refiners/refineAsyncResult.js.map +1 -1
  68. package/esm/refiners/refineAsyncResultU.js.map +1 -1
  69. package/esm/refiners/refineResult.js.map +1 -1
  70. package/esm/refiners/refineResultU.js.map +1 -1
  71. package/esm/refiners/refineVariantMap.js.map +1 -1
  72. package/esm/refiners/utils/getPayloadKeys.js.map +1 -1
  73. package/package.json +1 -1
  74. package/types/constructors/Err.d.ts +4 -4
  75. package/types/constructors/Err.d.ts.map +1 -1
  76. package/types/constructors/Ok.d.ts +4 -4
  77. package/types/constructors/Ok.d.ts.map +1 -1
  78. package/types/guards/isErr.d.ts +5 -5
  79. package/types/guards/isErr.d.ts.map +1 -1
  80. package/types/guards/isErrAnd.d.ts +6 -6
  81. package/types/guards/isErrAnd.d.ts.map +1 -1
  82. package/types/guards/isOk.d.ts +5 -5
  83. package/types/guards/isOk.d.ts.map +1 -1
  84. package/types/guards/isOkAnd.d.ts +6 -6
  85. package/types/guards/isOkAnd.d.ts.map +1 -1
  86. package/types/index.d.ts +1 -0
  87. package/types/index.d.ts.map +1 -1
  88. package/types/methods/andThen.d.ts +7 -7
  89. package/types/methods/andThen.d.ts.map +1 -1
  90. package/types/methods/err.d.ts +7 -8
  91. package/types/methods/err.d.ts.map +1 -1
  92. package/types/methods/expect.d.ts +9 -9
  93. package/types/methods/expect.d.ts.map +1 -1
  94. package/types/methods/expectErr.d.ts +9 -9
  95. package/types/methods/expectErr.d.ts.map +1 -1
  96. package/types/methods/flatten.d.ts +3 -3
  97. package/types/methods/flatten.d.ts.map +1 -1
  98. package/types/methods/inspect.d.ts +8 -8
  99. package/types/methods/inspect.d.ts.map +1 -1
  100. package/types/methods/inspectErr.d.ts +8 -8
  101. package/types/methods/inspectErr.d.ts.map +1 -1
  102. package/types/methods/map.d.ts +9 -9
  103. package/types/methods/map.d.ts.map +1 -1
  104. package/types/methods/mapErr.d.ts +8 -8
  105. package/types/methods/mapErr.d.ts.map +1 -1
  106. package/types/methods/match.d.ts +8 -8
  107. package/types/methods/match.d.ts.map +1 -1
  108. package/types/methods/ok.d.ts +7 -8
  109. package/types/methods/ok.d.ts.map +1 -1
  110. package/types/methods/orElse.d.ts +9 -9
  111. package/types/methods/orElse.d.ts.map +1 -1
  112. package/types/methods/tap.d.ts +7 -7
  113. package/types/methods/tap.d.ts.map +1 -1
  114. package/types/methods/tapErr.d.ts +7 -7
  115. package/types/methods/tapErr.d.ts.map +1 -1
  116. package/types/methods/transpose.d.ts +5 -6
  117. package/types/methods/transpose.d.ts.map +1 -1
  118. package/types/methods/unwrap.d.ts +8 -8
  119. package/types/methods/unwrap.d.ts.map +1 -1
  120. package/types/methods/unwrapErr.d.ts +8 -8
  121. package/types/methods/unwrapErr.d.ts.map +1 -1
  122. package/types/methods/unwrapOr.d.ts +8 -8
  123. package/types/methods/unwrapOr.d.ts.map +1 -1
  124. package/types/methods/unwrapOrElse.d.ts +8 -8
  125. package/types/methods/unwrapOrElse.d.ts.map +1 -1
  126. package/types/refiners/isTypedVariant.d.ts +3 -3
  127. package/types/refiners/isTypedVariantOf.d.ts +3 -3
  128. package/types/refiners/matchVariant.d.ts +5 -5
  129. package/types/refiners/matchVariantStrict.d.ts +6 -6
  130. package/types/refiners/refineAsyncResult.d.ts +17 -15
  131. package/types/refiners/refineAsyncResult.d.ts.map +1 -1
  132. package/types/refiners/refineAsyncResultU.d.ts +13 -11
  133. package/types/refiners/refineAsyncResultU.d.ts.map +1 -1
  134. package/types/refiners/refineResult.d.ts +18 -16
  135. package/types/refiners/refineResult.d.ts.map +1 -1
  136. package/types/refiners/refineResultU.d.ts +13 -11
  137. package/types/refiners/refineResultU.d.ts.map +1 -1
  138. package/types/refiners/refineVariantMap.d.ts +8 -8
  139. package/types/refiners/refineVariantMap.d.ts.map +1 -1
  140. package/types/refiners/types/Handler.d.ts +9 -1
  141. package/types/refiners/types/Handler.d.ts.map +1 -1
  142. package/types/refiners/types/MatchBuilder.d.ts +20 -1
  143. package/types/refiners/types/MatchBuilder.d.ts.map +1 -1
  144. package/types/refiners/types/Matcher.d.ts +23 -1
  145. package/types/refiners/types/Matcher.d.ts.map +1 -1
  146. package/types/refiners/types/SyncRefinedResult.d.ts +26 -2
  147. package/types/refiners/types/SyncRefinedResult.d.ts.map +1 -1
  148. package/types/refiners/types/SyncRefinedResultUnion.d.ts +25 -2
  149. package/types/refiners/types/SyncRefinedResultUnion.d.ts.map +1 -1
  150. package/types/refiners/types/SyncValidatorMap.d.ts +26 -2
  151. package/types/refiners/types/SyncValidatorMap.d.ts.map +1 -1
  152. package/types/refiners/types/UniversalAsyncRefinedResult.d.ts +28 -2
  153. package/types/refiners/types/UniversalAsyncRefinedResult.d.ts.map +1 -1
  154. package/types/refiners/types/UniversalRefinedResult.d.ts +28 -2
  155. package/types/refiners/types/UniversalRefinedResult.d.ts.map +1 -1
  156. package/types/refiners/types/VariantOf.d.ts +20 -1
  157. package/types/refiners/types/VariantOf.d.ts.map +1 -1
  158. package/types/refiners/utils/getPayloadKeys.d.ts +6 -5
  159. package/types/refiners/utils/getPayloadKeys.d.ts.map +1 -1
  160. package/types/types/core/index.d.ts +3 -0
  161. package/types/types/core/index.d.ts.map +1 -0
  162. package/types/types/index.d.ts +1 -2
  163. package/types/types/index.d.ts.map +1 -1
  164. package/umd/resultsafe-monorepo-core-fp-result.umd.js.map +1 -1
  165. package/types/shared-types.d.ts +0 -22
  166. package/types/shared-types.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,305 +1,355 @@
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)
1
+ # @resultsafe/core-fp-result
2
+
3
+ <a id="top"></a>
4
+
5
+ ![ResultSafe Logo](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/docs/assets/logo.svg)
6
+
7
+ ## 🤖 AI Context
8
+
9
+ This package implements the `Result<T, E>` pattern for explicit error handling without `try/catch`.
10
+
11
+ - **Rust analogue:** `std::result::Result`
12
+ - **Scala analogue:** `Either`
13
+ - **Core principle:** Error is a value, not an exception.
14
+
15
+ [![npm version](https://img.shields.io/npm/v/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
16
+ [![npm downloads](https://img.shields.io/npm/dm/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
17
+ [![license](https://img.shields.io/npm/l/@resultsafe/core-fp-result.svg)](./LICENSE)
18
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6.svg)](https://www.typescriptlang.org/)
19
+ [![docs](https://img.shields.io/badge/docs-api-informational.svg)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
20
+ [![build status](https://img.shields.io/badge/build-local%20verified-success.svg)](./package.json)
21
+ [![monorepo](https://img.shields.io/badge/monorepo-resultsafe%2Fmonorepo-0A0A0A.svg)](https://github.com/Livooon/resultsafe)
22
+
23
+ A Rust-inspired Result package for explicit, composable, and type-friendly APIs in TypeScript and JavaScript.
24
+
25
+ **Language:** English | [Русский](https://github.com/resultsafe/monorepo/blob/main/packages/core/fp/result/README.ru.md)
26
+
27
+ **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)
28
+
29
+ ---
30
+
31
+ ## Contents
32
+
33
+ - [Why this package](#why-this-package)
34
+ - [Monorepo context](#monorepo-context)
35
+ - [Key features](#key-features)
36
+ - [Package](#package)
37
+ - [Installation](#installation)
38
+ - [Quick start](#quick-start)
39
+ - [Core API overview](#core-api-overview)
40
+ - [Build and distribution formats](#build-and-distribution-formats)
41
+ - [Monorepo and package structure](#monorepo-and-package-structure)
42
+ - [When to use this project](#when-to-use-this-project)
43
+ - [Documentation for developers](#documentation-for-developers)
44
+ - [Documentation links](#documentation-links)
45
+ - [License](#license)
46
+
47
+ ---
48
+
49
+ ## Why this package
50
+
51
+ `@resultsafe/core-fp-result` provides explicit success/error flows instead of hidden control paths and exception-first branching.
52
+
53
+ 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:
54
+
55
+ - explicit `Ok` / `Err`
56
+ - predictable functional composition
57
+ - safe branching through guards and matching
58
+ - disciplined extraction APIs
59
+ - advanced refinement utilities for typed variants and strict matching
60
+
61
+ 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.
62
+
63
+ ---
64
+
65
+ ## Monorepo context
66
+
67
+ `@resultsafe/core-fp-result` is the TypeScript/JavaScript package inside the multilingual `resultsafe/monorepo`.
68
+
69
+ 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.
70
+
71
+ ---
72
+
73
+ ## Key features
74
+
75
+ - Rust-inspired `Result` model for TypeScript and JavaScript.
76
+ - Explicit constructors via `Ok` and `Err`.
77
+ - Composable transformations with APIs such as `map`, `mapErr`, `andThen`, and `orElse`.
78
+ - Safe branching through guards like `isOk`, `isErr`, `isOkAnd`, `isErrAnd`, and matching helpers.
79
+ - Controlled extraction with `unwrap`, `unwrapOr`, `unwrapErr`, `expect`, and `expectErr`.
80
+ - Advanced refinement layer for typed variants, strict matching, and result narrowing.
81
+ - Coherent module structure instead of a flat utility dump.
82
+ - Type output for TypeScript users for better DX and safer integrations.
83
+ - Flexible distribution formats with Types, ESM, CJS, and UMD builds.
84
+
85
+ ---
86
+
87
+ ## Package
88
+
89
+ ### `@resultsafe/core-fp-result`
90
+
91
+ A focused Result library for explicit error handling and FP-style composition.
92
+
93
+ It is designed for developers who want:
94
+
95
+ - clear success/error modeling
96
+ - predictable transformations
97
+ - explicit branching and extraction
98
+ - better readability in error-heavy flows
99
+ - a structured Rust-inspired API surface in TypeScript/JavaScript
100
+
101
+ ---
102
+
103
+ ## Installation
104
+
105
+ ### Package
106
+
107
+ ```bash
108
+ pnpm add @resultsafe/core-fp-result
109
+
110
+ # Alternative
111
+ npm install @resultsafe/core-fp-result
112
+ ```
113
+
114
+ ### Monorepo
115
+
116
+ ```bash
117
+ pnpm install
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Quick start
123
+
124
+ A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
125
+
126
+ ```ts
127
+ import { Ok, map, unwrapOr } from '@resultsafe/core-fp-result';
128
+
129
+ const initial = Ok(21);
130
+ const doubled = map(initial, (value) => value * 2);
131
+ const finalValue = unwrapOr(doubled, 0);
132
+
133
+ console.log(finalValue); // 42
134
+ ```
135
+
136
+ ### Basic `Ok` / `Err` example
137
+
138
+ ```ts
139
+ import { Ok, Err, match } from '@resultsafe/core-fp-result';
140
+
141
+ const parsePort = (input: string) => {
142
+ const port = Number(input);
143
+ return Number.isInteger(port) && port > 0 ? Ok(port) : Err('Invalid port');
144
+ };
145
+
146
+ const result = parsePort('3000');
147
+ const message = match(
148
+ result,
149
+ (value) => `Port: ${value}`,
150
+ (error) => `Error: ${error}`,
151
+ );
152
+
153
+ console.log(message);
154
+ ```
155
+
156
+ ---
157
+
158
+ ## API Reference
159
+
160
+ ### Core Functions
161
+
162
+ | Function | Signature | Description | GitHub | Raw |
163
+ | ----------- | ----------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
164
+ | `Ok` | `(value: T) => Result<T, E>` | Success constructor | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Ok.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts) |
165
+ | `Err` | `(error: E) => Result<T, E>` | Error constructor | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Err.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts) |
166
+ | `match` | `(r, onOk, onErr) => U` | Branch on result | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/match.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts) |
167
+ | `andThen` | `(r, fn) => Result<U, E>` | Chain (flatMap) | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/andThen.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts) |
168
+ | `map` | `(r, fn) => Result<U, E>` | Transform success value | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/map.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts) |
169
+ | `mapErr` | `(r, fn) => Result<T, U>` | Transform error value | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/mapErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts) |
170
+ | `orElse` | `(r, fn) => Result<T, U>` | Recover from error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/orElse.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts) |
171
+ | `unwrap` | `(r) => T` | Extract value or throw | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrap.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts) |
172
+ | `unwrapOr` | `(r, fallback: T) => T` | Extract value or default | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts) |
173
+ | `expect` | `(r, msg: string) => T` | Extract value or throw with message | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expect.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts) |
174
+ | `isOk` | `(r) => boolean` | Check if success | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOk.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts) |
175
+ | `isErr` | `(r) => boolean` | Check if error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts) |
176
+ | `tap` | `(r, fn) => Result<T, E>` | Side effect on success | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tap.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts) |
177
+ | `tapErr` | `(r, fn) => Result<T, E>` | Side effect on error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tapErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts) |
178
+ | `transpose` | `(r) => Option<Result<T, E>>` | Result<Option> to Option<Result> | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/transpose.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts) |
179
+ | `flatten` | `(r) => Result<T, E>` | Flatten nested Result | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/flatten.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts) |
180
+
181
+ ### Advanced: Refiners
182
+
183
+ | Function | Description | GitHub | Raw |
184
+ | -------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
185
+ | `isTypedVariant` | Type guard for variant | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) |
186
+ | `matchVariant` | Match variant with handlers | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariant.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts) |
187
+ | `matchVariantStrict` | Strict variant matching | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) |
188
+ | `refineResult` | Sync result refinement | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResult.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts) |
189
+ | `refineAsyncResult` | Async result refinement | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) |
190
+
191
+ ### Type Aliases
192
+
193
+ | Type | Description | GitHub | Raw |
194
+ | ------------------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
195
+ | `Result<T, E>` | Base success/error type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Result.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts) |
196
+ | `Option<T>` | Optional value type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Option.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts) |
197
+ | `VariantConfig` | Variant configuration type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) |
198
+ | `ValidatorFn<T>` | Sync validator function type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) |
199
+ | `AsyncValidatorFn` | Async validator function type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) |
200
+
201
+ > **Full API:** [All modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md) · [Constructors](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md) · [Guards](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md) · [Methods](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md) · [Refiners](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
202
+
203
+ ---
204
+
205
+ ## Examples
206
+
207
+ ### Example 1: Basic Usage
208
+
209
+ ```typescript
210
+ import { Ok, Err, match } from '@resultsafe/core-fp-result';
211
+
212
+ const result = Ok(42);
213
+ match(
214
+ result,
215
+ (value) => console.log(value),
216
+ (error) => console.error(error),
217
+ );
218
+ ```
219
+
220
+ ### Example 2: Error Handling
221
+
222
+ ```typescript
223
+ import { Ok, Err } from '@resultsafe/core-fp-result';
224
+
225
+ const divide = (a: number, b: number) =>
226
+ b === 0 ? Err('Division by zero') : Ok(a / b);
227
+
228
+ const result = divide(10, 0);
229
+ // Err("Division by zero")
230
+ ```
231
+
232
+ ### Example 3: Chaining Operations
233
+
234
+ ```typescript
235
+ import { Ok, andThen, map } from '@resultsafe/core-fp-result';
236
+
237
+ const result = Ok(5);
238
+ const doubled = andThen(result, (x) => Ok(x * 2));
239
+ const squared = map(doubled, (x) => x ** 2);
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Ecosystem
245
+
246
+ - `@resultsafe/core-fp-option` — Option/Maybe type
247
+ - `@resultsafe/core-fp-either` — Either type
248
+ - `@resultsafe/core-fp-result` — This package (Result type)
249
+
250
+ All packages follow the same API design pattern.
251
+
252
+ ---
253
+
254
+ ## Build and distribution formats
255
+
256
+ - Types: `build:types`
257
+ - ESM: `build:esm`
258
+ - CJS: `build:cjs`
259
+ - UMD: `build:umd`
260
+
261
+ This package ships typed declarations and multiple runtime module formats for broad compatibility.
262
+
263
+ ---
264
+
265
+ ## Monorepo and package structure
266
+
267
+ ```txt
268
+ src/
269
+ constructors/
270
+ guards/
271
+ methods/
272
+ refiners/
273
+ types/
274
+ utils/
275
+ internal/
276
+ index.ts
277
+ ```
278
+
279
+ ---
280
+
281
+ ## When to use this project
282
+
283
+ Use this project when you want:
284
+
285
+ - explicit success/error modeling
286
+ - predictable FP-style composition
287
+ - visible control flow
288
+ - stronger type-guided result handling in TypeScript
289
+ - advanced refinement tools for typed variants and strict result matching
290
+
291
+ ---
292
+
293
+ ## Documentation for developers
294
+
295
+ This package includes comprehensive documentation for developers working with the codebase:
296
+
297
+ ### AI-Optimized JSDoc Standard
298
+
299
+ The package uses an AI-optimized JSDoc documentation standard designed for:
300
+
301
+ - **RAG systems** — Retrieval-Augmented Generation, vector search (Google NotebookLM, LangChain)
302
+ - **LLM training** — Fine-tuning, code completion, instruction tuning
303
+ - **Code Search** — Semantic search (GitHub Copilot, Cursor, Sourcegraph)
304
+ - **Auto-complete** — Context-aware suggestions
305
+ - **Human developers** — Readability, navigation, learning
306
+
307
+ **Documentation:** [`__examples__/AI_JSDOC_STANDARD.md`](./__examples__/AI_JSDOC_STANDARD.md)
308
+
309
+ ### CI/CD Integration
310
+
311
+ Examples are validated through GitHub Actions workflow:
312
+
313
+ - **AI JSDoc JSON validation** — Validates `@ai` JSON structure in all example files
314
+ - **ESLint checks** — Ensures code quality and JSDoc presence
315
+ - **Type checking** — Validates TypeScript syntax in examples
316
+ - **Automated testing** — Runs example tests on push/PR
317
+
318
+ **Documentation:** [`__examples__/CI_CD_INTEGRATION.md`](./__examples__/CI_CD_INTEGRATION.md)
319
+
320
+ ### Example structure
321
+
322
+ Examples are organized into structured directories:
323
+
324
+ - `00-quick-start/` — Getting started examples
325
+ - `01-api-reference/` — API documentation with examples
326
+ - `02-patterns/` — Real-world usage patterns
327
+
328
+ ---
329
+
330
+ ## Documentation links
331
+
332
+ - [API entry (README)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
333
+ - [API entry (index)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/index.md)
334
+ - [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
335
+ - [Constructors module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md)
336
+ - [Guards module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md)
337
+ - [Methods module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md)
338
+ - [Refiners module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
339
+ - [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
340
+
341
+ ---
342
+
343
+ Back to top: [@resultsafe/core-fp-result](#top)
344
+
345
+ ---
346
+
347
+ ## Author
348
+
349
+ Denis Savasteev
350
+
351
+ ---
352
+
353
+ ## License
354
+
355
+ [MIT](./LICENSE)