@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.
- package/README.md +355 -305
- package/cjs/constructors/Err.js.map +1 -1
- package/cjs/constructors/Ok.js.map +1 -1
- package/cjs/guards/isErr.js.map +1 -1
- package/cjs/guards/isErrAnd.js.map +1 -1
- package/cjs/guards/isOk.js.map +1 -1
- package/cjs/guards/isOkAnd.js.map +1 -1
- package/cjs/methods/andThen.js.map +1 -1
- package/cjs/methods/err.js.map +1 -1
- package/cjs/methods/expect.js.map +1 -1
- package/cjs/methods/expectErr.js.map +1 -1
- package/cjs/methods/flatten.js.map +1 -1
- package/cjs/methods/inspect.js.map +1 -1
- package/cjs/methods/inspectErr.js.map +1 -1
- package/cjs/methods/map.js.map +1 -1
- package/cjs/methods/mapErr.js.map +1 -1
- package/cjs/methods/match.js.map +1 -1
- package/cjs/methods/ok.js.map +1 -1
- package/cjs/methods/orElse.js.map +1 -1
- package/cjs/methods/tap.js.map +1 -1
- package/cjs/methods/tapErr.js.map +1 -1
- package/cjs/methods/transpose.js.map +1 -1
- package/cjs/methods/unwrap.js.map +1 -1
- package/cjs/methods/unwrapErr.js.map +1 -1
- package/cjs/methods/unwrapOr.js.map +1 -1
- package/cjs/methods/unwrapOrElse.js.map +1 -1
- package/cjs/refiners/isTypedVariant.js.map +1 -1
- package/cjs/refiners/isTypedVariantOf.js.map +1 -1
- package/cjs/refiners/matchVariant.js.map +1 -1
- package/cjs/refiners/matchVariantStrict.js.map +1 -1
- package/cjs/refiners/refineAsyncResult.js.map +1 -1
- package/cjs/refiners/refineAsyncResultU.js.map +1 -1
- package/cjs/refiners/refineResult.js.map +1 -1
- package/cjs/refiners/refineResultU.js.map +1 -1
- package/cjs/refiners/refineVariantMap.js.map +1 -1
- package/cjs/refiners/utils/getPayloadKeys.js.map +1 -1
- package/docs/assets/logo.svg +0 -0
- package/esm/constructors/Err.js.map +1 -1
- package/esm/constructors/Ok.js.map +1 -1
- package/esm/guards/isErr.js.map +1 -1
- package/esm/guards/isErrAnd.js.map +1 -1
- package/esm/guards/isOk.js.map +1 -1
- package/esm/guards/isOkAnd.js.map +1 -1
- package/esm/methods/andThen.js.map +1 -1
- package/esm/methods/err.js.map +1 -1
- package/esm/methods/expect.js.map +1 -1
- package/esm/methods/expectErr.js.map +1 -1
- package/esm/methods/flatten.js.map +1 -1
- package/esm/methods/inspect.js.map +1 -1
- package/esm/methods/inspectErr.js.map +1 -1
- package/esm/methods/map.js.map +1 -1
- package/esm/methods/mapErr.js.map +1 -1
- package/esm/methods/match.js.map +1 -1
- package/esm/methods/ok.js.map +1 -1
- package/esm/methods/orElse.js.map +1 -1
- package/esm/methods/tap.js.map +1 -1
- package/esm/methods/tapErr.js.map +1 -1
- package/esm/methods/transpose.js.map +1 -1
- package/esm/methods/unwrap.js.map +1 -1
- package/esm/methods/unwrapErr.js.map +1 -1
- package/esm/methods/unwrapOr.js.map +1 -1
- package/esm/methods/unwrapOrElse.js.map +1 -1
- package/esm/refiners/isTypedVariant.js.map +1 -1
- package/esm/refiners/isTypedVariantOf.js.map +1 -1
- package/esm/refiners/matchVariant.js.map +1 -1
- package/esm/refiners/matchVariantStrict.js.map +1 -1
- package/esm/refiners/refineAsyncResult.js.map +1 -1
- package/esm/refiners/refineAsyncResultU.js.map +1 -1
- package/esm/refiners/refineResult.js.map +1 -1
- package/esm/refiners/refineResultU.js.map +1 -1
- package/esm/refiners/refineVariantMap.js.map +1 -1
- package/esm/refiners/utils/getPayloadKeys.js.map +1 -1
- package/package.json +1 -1
- package/types/constructors/Err.d.ts +4 -4
- package/types/constructors/Err.d.ts.map +1 -1
- package/types/constructors/Ok.d.ts +4 -4
- package/types/constructors/Ok.d.ts.map +1 -1
- package/types/guards/isErr.d.ts +5 -5
- package/types/guards/isErr.d.ts.map +1 -1
- package/types/guards/isErrAnd.d.ts +6 -6
- package/types/guards/isErrAnd.d.ts.map +1 -1
- package/types/guards/isOk.d.ts +5 -5
- package/types/guards/isOk.d.ts.map +1 -1
- package/types/guards/isOkAnd.d.ts +6 -6
- package/types/guards/isOkAnd.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/methods/andThen.d.ts +7 -7
- package/types/methods/andThen.d.ts.map +1 -1
- package/types/methods/err.d.ts +7 -8
- package/types/methods/err.d.ts.map +1 -1
- package/types/methods/expect.d.ts +9 -9
- package/types/methods/expect.d.ts.map +1 -1
- package/types/methods/expectErr.d.ts +9 -9
- package/types/methods/expectErr.d.ts.map +1 -1
- package/types/methods/flatten.d.ts +3 -3
- package/types/methods/flatten.d.ts.map +1 -1
- package/types/methods/inspect.d.ts +8 -8
- package/types/methods/inspect.d.ts.map +1 -1
- package/types/methods/inspectErr.d.ts +8 -8
- package/types/methods/inspectErr.d.ts.map +1 -1
- package/types/methods/map.d.ts +9 -9
- package/types/methods/map.d.ts.map +1 -1
- package/types/methods/mapErr.d.ts +8 -8
- package/types/methods/mapErr.d.ts.map +1 -1
- package/types/methods/match.d.ts +8 -8
- package/types/methods/match.d.ts.map +1 -1
- package/types/methods/ok.d.ts +7 -8
- package/types/methods/ok.d.ts.map +1 -1
- package/types/methods/orElse.d.ts +9 -9
- package/types/methods/orElse.d.ts.map +1 -1
- package/types/methods/tap.d.ts +7 -7
- package/types/methods/tap.d.ts.map +1 -1
- package/types/methods/tapErr.d.ts +7 -7
- package/types/methods/tapErr.d.ts.map +1 -1
- package/types/methods/transpose.d.ts +5 -6
- package/types/methods/transpose.d.ts.map +1 -1
- package/types/methods/unwrap.d.ts +8 -8
- package/types/methods/unwrap.d.ts.map +1 -1
- package/types/methods/unwrapErr.d.ts +8 -8
- package/types/methods/unwrapErr.d.ts.map +1 -1
- package/types/methods/unwrapOr.d.ts +8 -8
- package/types/methods/unwrapOr.d.ts.map +1 -1
- package/types/methods/unwrapOrElse.d.ts +8 -8
- package/types/methods/unwrapOrElse.d.ts.map +1 -1
- package/types/refiners/isTypedVariant.d.ts +3 -3
- package/types/refiners/isTypedVariantOf.d.ts +3 -3
- package/types/refiners/matchVariant.d.ts +5 -5
- package/types/refiners/matchVariantStrict.d.ts +6 -6
- package/types/refiners/refineAsyncResult.d.ts +17 -15
- package/types/refiners/refineAsyncResult.d.ts.map +1 -1
- package/types/refiners/refineAsyncResultU.d.ts +13 -11
- package/types/refiners/refineAsyncResultU.d.ts.map +1 -1
- package/types/refiners/refineResult.d.ts +18 -16
- package/types/refiners/refineResult.d.ts.map +1 -1
- package/types/refiners/refineResultU.d.ts +13 -11
- package/types/refiners/refineResultU.d.ts.map +1 -1
- package/types/refiners/refineVariantMap.d.ts +8 -8
- package/types/refiners/refineVariantMap.d.ts.map +1 -1
- package/types/refiners/types/Handler.d.ts +9 -1
- package/types/refiners/types/Handler.d.ts.map +1 -1
- package/types/refiners/types/MatchBuilder.d.ts +20 -1
- package/types/refiners/types/MatchBuilder.d.ts.map +1 -1
- package/types/refiners/types/Matcher.d.ts +23 -1
- package/types/refiners/types/Matcher.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResult.d.ts +26 -2
- package/types/refiners/types/SyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts +25 -2
- package/types/refiners/types/SyncRefinedResultUnion.d.ts.map +1 -1
- package/types/refiners/types/SyncValidatorMap.d.ts +26 -2
- package/types/refiners/types/SyncValidatorMap.d.ts.map +1 -1
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts +28 -2
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/UniversalRefinedResult.d.ts +28 -2
- package/types/refiners/types/UniversalRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/VariantOf.d.ts +20 -1
- package/types/refiners/types/VariantOf.d.ts.map +1 -1
- package/types/refiners/utils/getPayloadKeys.d.ts +6 -5
- package/types/refiners/utils/getPayloadKeys.d.ts.map +1 -1
- package/types/types/core/index.d.ts +3 -0
- package/types/types/core/index.d.ts.map +1 -0
- package/types/types/index.d.ts +1 -2
- package/types/types/index.d.ts.map +1 -1
- package/umd/resultsafe-monorepo-core-fp-result.umd.js.map +1 -1
- package/types/shared-types.d.ts +0 -22
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[
|
|
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
|
+
[](https://www.npmjs.com/package/@resultsafe/core-fp-result)
|
|
16
|
+
[](https://www.npmjs.com/package/@resultsafe/core-fp-result)
|
|
17
|
+
[](./LICENSE)
|
|
18
|
+
[](https://www.typescriptlang.org/)
|
|
19
|
+
[](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
|
|
20
|
+
[](./package.json)
|
|
21
|
+
[](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)
|