@resultsafe/core-fp-result 0.1.9 โ 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -83
- package/README.ru.md +304 -302
- package/docs/assets/logo.svg +0 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.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 +23 -1
- package/types/refiners/types/SyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts +24 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts.map +1 -1
- package/types/refiners/types/SyncValidatorMap.d.ts +23 -1
- package/types/refiners/types/SyncValidatorMap.d.ts.map +1 -1
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts +27 -1
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/UniversalRefinedResult.d.ts +27 -1
- 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/shared-types.d.ts +142 -0
- package/types/shared-types.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# @resultsafe/core-fp-result
|
|
2
|
+
|
|
2
3
|
<a id="top"></a>
|
|
3
4
|
|
|
4
5
|

|
|
5
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
|
+
|
|
6
15
|
[](https://www.npmjs.com/package/@resultsafe/core-fp-result)
|
|
7
16
|
[](https://www.npmjs.com/package/@resultsafe/core-fp-result)
|
|
8
17
|
[](./LICENSE)
|
|
@@ -18,6 +27,7 @@ A Rust-inspired Result package for explicit, composable, and type-friendly APIs
|
|
|
18
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)
|
|
19
28
|
|
|
20
29
|
---
|
|
30
|
+
|
|
21
31
|
## Contents
|
|
22
32
|
|
|
23
33
|
- [Why this package](#why-this-package)
|
|
@@ -113,11 +123,7 @@ pnpm install
|
|
|
113
123
|
A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
|
|
114
124
|
|
|
115
125
|
```ts
|
|
116
|
-
import {
|
|
117
|
-
Ok,
|
|
118
|
-
map,
|
|
119
|
-
unwrapOr,
|
|
120
|
-
} from "@resultsafe/core-fp-result";
|
|
126
|
+
import { Ok, map, unwrapOr } from '@resultsafe/core-fp-result';
|
|
121
127
|
|
|
122
128
|
const initial = Ok(21);
|
|
123
129
|
const doubled = map(initial, (value) => value * 2);
|
|
@@ -129,111 +135,118 @@ console.log(finalValue); // 42
|
|
|
129
135
|
### Basic `Ok` / `Err` example
|
|
130
136
|
|
|
131
137
|
```ts
|
|
132
|
-
import { Ok, Err, match } from
|
|
138
|
+
import { Ok, Err, match } from '@resultsafe/core-fp-result';
|
|
133
139
|
|
|
134
140
|
const parsePort = (input: string) => {
|
|
135
141
|
const port = Number(input);
|
|
136
|
-
return Number.isInteger(port) && port > 0
|
|
137
|
-
? Ok(port)
|
|
138
|
-
: Err("Invalid port");
|
|
142
|
+
return Number.isInteger(port) && port > 0 ? Ok(port) : Err('Invalid port');
|
|
139
143
|
};
|
|
140
144
|
|
|
141
|
-
const result = parsePort(
|
|
142
|
-
const message = match(
|
|
145
|
+
const result = parsePort('3000');
|
|
146
|
+
const message = match(
|
|
147
|
+
result,
|
|
148
|
+
(value) => `Port: ${value}`,
|
|
149
|
+
(error) => `Error: ${error}`,
|
|
150
|
+
);
|
|
143
151
|
|
|
144
152
|
console.log(message);
|
|
145
153
|
```
|
|
146
154
|
|
|
147
155
|
---
|
|
148
156
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
## API Reference
|
|
158
|
+
|
|
159
|
+
### Core Functions
|
|
160
|
+
|
|
161
|
+
| Function | Signature | Description | GitHub | Raw |
|
|
162
|
+
| ----------- | ----------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
163
|
+
| `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) |
|
|
164
|
+
| `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) |
|
|
165
|
+
| `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) |
|
|
166
|
+
| `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) |
|
|
167
|
+
| `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) |
|
|
168
|
+
| `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) |
|
|
169
|
+
| `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) |
|
|
170
|
+
| `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) |
|
|
171
|
+
| `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) |
|
|
172
|
+
| `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) |
|
|
173
|
+
| `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) |
|
|
174
|
+
| `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) |
|
|
175
|
+
| `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) |
|
|
176
|
+
| `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) |
|
|
177
|
+
| `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) |
|
|
178
|
+
| `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) |
|
|
179
|
+
|
|
180
|
+
### Advanced: Refiners
|
|
181
|
+
|
|
182
|
+
| Function | Description | GitHub | Raw |
|
|
183
|
+
| -------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
184
|
+
| `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) |
|
|
185
|
+
| `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) |
|
|
186
|
+
| `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) |
|
|
187
|
+
| `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) |
|
|
188
|
+
| `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) |
|
|
189
|
+
|
|
190
|
+
### Type Aliases
|
|
191
|
+
|
|
192
|
+
| Type | Description | GitHub | Raw |
|
|
193
|
+
| ------------------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
194
|
+
| `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) |
|
|
195
|
+
| `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) |
|
|
196
|
+
| `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) |
|
|
197
|
+
| `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) |
|
|
198
|
+
| `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) |
|
|
199
|
+
|
|
200
|
+
> **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)
|
|
165
201
|
|
|
166
|
-
|
|
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")
|
|
202
|
+
---
|
|
177
203
|
|
|
178
|
-
|
|
204
|
+
## Examples
|
|
179
205
|
|
|
180
|
-
|
|
206
|
+
### Example 1: Basic Usage
|
|
181
207
|
|
|
182
|
-
|
|
183
|
-
|
|
208
|
+
```typescript
|
|
209
|
+
import { Ok, Err, match } from '@resultsafe/core-fp-result';
|
|
184
210
|
|
|
185
|
-
|
|
211
|
+
const result = Ok(42);
|
|
212
|
+
match(
|
|
213
|
+
result,
|
|
214
|
+
(value) => console.log(value),
|
|
215
|
+
(error) => console.error(error),
|
|
216
|
+
);
|
|
217
|
+
```
|
|
186
218
|
|
|
187
|
-
|
|
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")
|
|
219
|
+
### Example 2: Error Handling
|
|
189
220
|
|
|
190
|
-
|
|
221
|
+
```typescript
|
|
222
|
+
import { Ok, Err } from '@resultsafe/core-fp-result';
|
|
191
223
|
|
|
192
|
-
|
|
193
|
-
|
|
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")
|
|
224
|
+
const divide = (a: number, b: number) =>
|
|
225
|
+
b === 0 ? Err('Division by zero') : Ok(a / b);
|
|
198
226
|
|
|
199
|
-
|
|
227
|
+
const result = divide(10, 0);
|
|
228
|
+
// Err("Division by zero")
|
|
229
|
+
```
|
|
200
230
|
|
|
201
|
-
|
|
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")
|
|
231
|
+
### Example 3: Chaining Operations
|
|
205
232
|
|
|
206
|
-
|
|
233
|
+
```typescript
|
|
234
|
+
import { Ok, andThen, map } from '@resultsafe/core-fp-result';
|
|
207
235
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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")
|
|
236
|
+
const result = Ok(5);
|
|
237
|
+
const doubled = andThen(result, (x) => Ok(x * 2));
|
|
238
|
+
const squared = map(doubled, (x) => x ** 2);
|
|
239
|
+
```
|
|
213
240
|
|
|
214
|
-
|
|
241
|
+
---
|
|
215
242
|
|
|
216
|
-
|
|
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")
|
|
243
|
+
## Ecosystem
|
|
225
244
|
|
|
226
|
-
|
|
245
|
+
- `@resultsafe/core-fp-option` โ Option/Maybe type
|
|
246
|
+
- `@resultsafe/core-fp-either` โ Either type
|
|
247
|
+
- `@resultsafe/core-fp-result` โ This package (Result type)
|
|
227
248
|
|
|
228
|
-
|
|
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")
|
|
249
|
+
All packages follow the same API design pattern.
|
|
237
250
|
|
|
238
251
|
---
|
|
239
252
|
|
|
@@ -288,9 +301,11 @@ Use this project when you want:
|
|
|
288
301
|
- [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
|
|
289
302
|
|
|
290
303
|
---
|
|
304
|
+
|
|
291
305
|
Back to top: [@resultsafe/core-fp-result](#top)
|
|
292
306
|
|
|
293
307
|
---
|
|
308
|
+
|
|
294
309
|
## Author
|
|
295
310
|
|
|
296
311
|
Denis Savasteev
|