@carbonteq/fp 0.6.0 → 0.8.0-alpha.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/LICENSE +21 -0
- package/README.md +610 -1
- package/package.json +66 -73
- package/lib/index.d.ts +0 -7
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -1
- package/lib/index.mjs +0 -1
- package/lib/match.d.ts +0 -11
- package/lib/match.d.ts.map +0 -1
- package/lib/option.d.ts +0 -57
- package/lib/option.d.ts.map +0 -1
- package/lib/result.d.ts +0 -149
- package/lib/result.d.ts.map +0 -1
- package/lib/tuple.d.ts +0 -9
- package/lib/tuple.d.ts.map +0 -1
- package/lib/unit.d.ts +0 -3
- package/lib/unit.d.ts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Carbonteq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,610 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Carbonteq Functional Programming Utilities (fp)
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`fp` is a lightweight TypeScript library designed to simplify functional programming by providing essential types like `Option` and `Result`. It helps developers handle errors, manage optional values, and write expressive, composable code.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @carbonteq/fp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm i @carbonteq/fp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
yarn add @carbonteq/fp
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
bun add @carbonteq/fp
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# But why fp?
|
|
26
|
+
|
|
27
|
+
In JavaScript and TypeScript, dealing with `null`, `undefined`, and errors can lead to verbose, error-prone code. `fp` introduces functional paradigms that make handling these cases cleaner and more reliable. By leveraging `fp`, you can reduce boilerplate, improve readability, and create more maintainable applications.
|
|
28
|
+
|
|
29
|
+
To demonstrate the utility of `fp`, let us consider a use case where we need to retrieve a user's email and address.
|
|
30
|
+
|
|
31
|
+
### Without using the `fp` library
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
function getUserByEmail(user: { email?: string }): string | null {
|
|
35
|
+
return user.email ? user.email : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getUserAdress(user: { email?: string }): string | null {
|
|
39
|
+
return user.email ? "Some Address" : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const email = getUserByEmail({ email: "test@test.com" });
|
|
43
|
+
if (email) {
|
|
44
|
+
const address = getUserAdress(email);
|
|
45
|
+
if (address) {
|
|
46
|
+
console.log(`User ${email} has address: ${address}`);
|
|
47
|
+
} else {
|
|
48
|
+
console.error("Address not found");
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
console.error("Email not found");
|
|
52
|
+
}
|
|
53
|
+
// Output: User test@test.com has address: Some Address
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Now imagine if we had more complex use cases that involved more than two optional values. We would have to nest if statements and handle errors manually. This is where `fp` comes in.
|
|
57
|
+
|
|
58
|
+
### With using the `fp` library
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Option, matchOpt } from "@carbonteq/fp";
|
|
62
|
+
|
|
63
|
+
function getUserByEmail(user: { email?: string }): Option<string> {
|
|
64
|
+
return user.email ? Option.Some(user.email) : Option.None;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getUserAddress(user: { email?: string }): Option<string> {
|
|
68
|
+
return user.email ? Option.Some("Some Address") : Option.None;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const res = getUserByEmail({ email: "test@test.com" }).flatZip((email) => getUserAddress({ email }));
|
|
72
|
+
|
|
73
|
+
matchOpt(res, {
|
|
74
|
+
Some: (res) => {
|
|
75
|
+
console.log(`User ${res[0]} has address: ${res[1]}`);
|
|
76
|
+
},
|
|
77
|
+
None: () => {
|
|
78
|
+
console.error("User or Address not found");
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
// Output: User test@test.com has address: Some Address
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
# Table of Contents
|
|
85
|
+
|
|
86
|
+
- [Usage](#usage)
|
|
87
|
+
- [The `Result` type](#the-result-type)
|
|
88
|
+
- [The `Option` type](#the-option-type)
|
|
89
|
+
- [Cheatsheet](#cheatsheet)
|
|
90
|
+
- [map](#map)
|
|
91
|
+
- [flatMap](#flatmap)
|
|
92
|
+
- [zip](#zip)
|
|
93
|
+
- [flatZip](#flatzip)
|
|
94
|
+
- [Comparison of map and zip](#comparison-of-map-flatmap-zip-and-flatzip)
|
|
95
|
+
- [Some Other Useful Functions](#some-other-useful-functions)
|
|
96
|
+
- [mapErr](#maperr)
|
|
97
|
+
- [mapOr](#mapor)
|
|
98
|
+
- [tap](#tap)
|
|
99
|
+
- [all](#all)
|
|
100
|
+
- [validate](#validate)
|
|
101
|
+
- [unwrap](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
102
|
+
- [safeUnwrapErr](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
103
|
+
- [unwrapOr](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
104
|
+
- [unwrapOrElse](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
105
|
+
- [safeUnwrap](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
106
|
+
- [unwrapErr](#unwrap-safeunwraperr-unwrapor-unwraporelse-safeunwrap-and-unwraperr)
|
|
107
|
+
- [Build Your First Pipeline](#build-your-first-pipeline)
|
|
108
|
+
- [Synchronous Pipeline](#synchronous-pipeline)
|
|
109
|
+
- [Asynchronous Pipeline](#asynchronous-pipeline)
|
|
110
|
+
|
|
111
|
+
# Usage
|
|
112
|
+
|
|
113
|
+
## The `Result` type
|
|
114
|
+
|
|
115
|
+
`Result` represents a value that can be either a success (`Ok`) or a failure (`Err`). It simplifies error handling by making success and failure explicit.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Result } from "@carbonteq/fp";
|
|
119
|
+
|
|
120
|
+
const res1: Result<number, string> = Result.Ok(5); // Contains the value 5
|
|
121
|
+
const res2: Result<number, string> = Result.Err("Some Error"); // Contains the error "Some Error"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## The `Option` type
|
|
125
|
+
|
|
126
|
+
The `Option` type represents a value that might or might not be present. It eliminates the need for manual checks for `null` or `undefined`.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { Option } from "@carbonteq/fp";
|
|
130
|
+
|
|
131
|
+
const opt1: Option<number> = Option.Some(5); // Contains the value 5
|
|
132
|
+
const opt2: Option<number> = Option.None; // Contains no value (None)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Cheatsheet
|
|
138
|
+
|
|
139
|
+
#### `map`
|
|
140
|
+
|
|
141
|
+
Transforms the `Some` or `Ok` value inside `Option` or `Result`.
|
|
142
|
+
|
|
143
|
+
Let's say we want to apply a 10% bonus to the account balance of a user.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { Option } from "@carbonteq/fp";
|
|
147
|
+
|
|
148
|
+
async function fetchUserBalanceFromDatabase(userId: string): Promise<Option<number>> {
|
|
149
|
+
// Simulate fetching balance from a database
|
|
150
|
+
await Promise.resolve(userId);
|
|
151
|
+
return Option.Some(100);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function applyBonus() {
|
|
155
|
+
const userId = "user123"; // Example user ID
|
|
156
|
+
const balanceOption = await Option.Some(userId)
|
|
157
|
+
.flatMap(fetchUserBalanceFromDatabase)
|
|
158
|
+
.map((balance) => balance * 1.1)
|
|
159
|
+
.toPromise(); // Apply a 10% bonus if balance exists
|
|
160
|
+
return balanceOption;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
console.log(await applyBonus()); // Output: Some(110)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### `flatMap`
|
|
167
|
+
|
|
168
|
+
`flatMap` is used to chain operations where each step returns an `Option` or `Result`. It avoids nested structures like `Option<Option<T>>` or `Result<Result<T, E>, E>` by "flattening" them into a single level.
|
|
169
|
+
|
|
170
|
+
Let's say we want to validate user input and then save it to a database:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { Result } from "@carbonteq/fp";
|
|
174
|
+
|
|
175
|
+
// Function to validate user input
|
|
176
|
+
const validateUserData = (name: string, age: number): Result<{ name: string; age: number }, Error> => {
|
|
177
|
+
if (name.trim() === "") {
|
|
178
|
+
return Result.Err(new Error("Name cannot be empty"));
|
|
179
|
+
}
|
|
180
|
+
if (age < 0 || age > 120) {
|
|
181
|
+
return Result.Err(new Error("Age must be between 0 and 120"));
|
|
182
|
+
}
|
|
183
|
+
return Result.Ok({ name, age });
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Simulated asynchronous task to save user data to a "database"
|
|
187
|
+
const saveUserData = async (user: { name: string; age: number }): Promise<Result<string, Error>> => {
|
|
188
|
+
// Simulate saving to database
|
|
189
|
+
await Promise.resolve(user);
|
|
190
|
+
return Result.Ok(`User ${user.name} saved successfully!`);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// Chaining validation and save using `flatMap`
|
|
194
|
+
const processUser = async (name: string, age: number): Promise<Result<string, Error>> => {
|
|
195
|
+
const validationResult = await validateUserData(name, age).flatMap(saveUserData).toPromise();
|
|
196
|
+
return validationResult;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
console.log(await processUser("Alice", 30)); // Output: Result.Ok("User Alice saved successfully!")
|
|
200
|
+
|
|
201
|
+
/* validationResult is of type Result<string, Error> instead of Result<Result<string, Error>, Error> (which is what would have happened if we used map instead of flatMap) */
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### `zip`
|
|
205
|
+
|
|
206
|
+
Creates a tuple `[T, U]` where the second value `U` is _derived_ from the first value `T` using a function `f`.
|
|
207
|
+
For example, suppose we want to pair the product's original price `T` and discounted price `U`.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { Result } from "@carbonteq/fp";
|
|
211
|
+
|
|
212
|
+
async function fetchProductPrice(productId: string): Promise<Result<number, Error>> {
|
|
213
|
+
// Simulate fetching price from a database
|
|
214
|
+
await Promise.resolve(productId);
|
|
215
|
+
return Result.Ok(100);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function applyDiscount(productId: string): Promise<Result<[number, number], Error>> {
|
|
219
|
+
const originalPrice = await Result.Ok(productId)
|
|
220
|
+
.flatMap(fetchProductPrice)
|
|
221
|
+
.zip((price) => price * 0.9)
|
|
222
|
+
.toPromise();
|
|
223
|
+
return originalPrice; //originalPrice is of type Result<[number, number], Error>
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
console.log(await applyDiscount("123")); // Output: Result.Ok([100, 90])
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Here `derivedPair` is a `Result<[number, number], Error>`. Note that `T` = `100` and `U` = `90`.
|
|
230
|
+
|
|
231
|
+
#### `flatZip`
|
|
232
|
+
|
|
233
|
+
Combines the current `Result<T, E>` with another `Result<U, E2>`, or the current `Option<T>` with another `Option<U>`. Unlike zip, which pairs a value with a derived one, flatZip works with **two independent Result/Option values** and combines their contents into a tuple `[T, U]`. It ensures the Result/Option values are Ok/Some to proceed; otherwise, it propagates the first encountered Err/None.
|
|
234
|
+
|
|
235
|
+
Lets say we want to combine the product price and product stock into a tuple `[number, number]`.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { Option } from "@carbonteq/fp";
|
|
239
|
+
|
|
240
|
+
// Simulated function to fetch product price
|
|
241
|
+
async function fetchProductPrice(productId: string): Promise<Option<number>> {
|
|
242
|
+
// Simulate fetching price from a database
|
|
243
|
+
await Promise.resolve(productId);
|
|
244
|
+
return Option.Some(100);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Simulated function to fetch product stock
|
|
248
|
+
async function fetchProductStock(productId: string): Promise<Option<number>> {
|
|
249
|
+
// Simulate fetching stock from a database
|
|
250
|
+
await Promise.resolve(productId);
|
|
251
|
+
return Option.Some(50);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Function to combine price and stock using flatZip
|
|
255
|
+
async function fetchProductDetails(productId: string): Promise<Option<[number, number]>> {
|
|
256
|
+
const productDetails = await Option.Some(productId).flatMap(fetchProductPrice).flatZip(fetchProductStock).toPromise();
|
|
257
|
+
return productDetails; // Option<[number, number]>
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log(await fetchProductDetails("123")); // Output: Option.Some([100, 50])
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Comparison of `map`, `flatMap`, `zip`, and `flatZip`
|
|
264
|
+
|
|
265
|
+
| **Method** | **`map`** | **`flatMap`** | **`zip`** | **`flatZip`** | |
|
|
266
|
+
| --------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | --- |
|
|
267
|
+
| **Purpose** | Transforms the value inside an `Ok` or `Some`. | Chains dependent computations where each computation returns a `Result` or `Option`. | Combines the current value with another derived value into a tuple `[T, U]`. | Combines two independent `Result` or `Option` values into a tuple `[T, U]`. |
|
|
268
|
+
| **Input** | A function `(val: T) => U`. | A function `(val: T) => Result<U, E2>` or `(val: T) => Option<U>` to transform the current value into another `Result` or `Option`. | A function `(val: T) => U` to derive a new value `U` from the current value `T`. | A function `(val: T) => Result<U, E2>` or `(val: T) => Option<U>` that returns another `Result` or `Option`. |
|
|
269
|
+
| **Output** | `Result<U, E>`, `Option<U>` | `Result<U, E>`, `Option<U>` | `Result<[T, U], E>`, `Option<[T, U]>` | `Result<[T, U], E>`, `Option<[T, U]>`. |
|
|
270
|
+
| **Error Propagation** | Propagates `Err`/`None` if the `Result`/`Option` is `Err`/`None`. | Propagates the first `Err`/`None` encountered in the chain. | Propagates `Err`/`None` if the current `Result`/`Option` or derived value is `Err`/`None`. | Propagates the first `Err`/`None` encountered between the two `Result`/`Option` values. |
|
|
271
|
+
| **Use Case** | When you want to transform a value inside `Ok`/`Some`. | When the next computation depends on the current value and returns a `Result`/`Option`. | When you want to pair the current value with a derived one. | When you want to combine two independent `Result`/`Option` values into a tuple. |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### Some Other Useful Functions
|
|
276
|
+
|
|
277
|
+
#### `mapErr`
|
|
278
|
+
|
|
279
|
+
Transforms the `Err` value inside `Result`.
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { Result } from "@carbonteq/fp";
|
|
283
|
+
|
|
284
|
+
// Simulated function to divide two numbers
|
|
285
|
+
function divideNumbers(a: number, b: number): Result<number, Error> {
|
|
286
|
+
if (b === 0) {
|
|
287
|
+
return Result.Err(new Error("Division by zero"));
|
|
288
|
+
}
|
|
289
|
+
return Result.Ok(a / b);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// A safe divide function that returns a Result with a string error message if the division by zero occurs, instead of throwing an exception
|
|
293
|
+
function safeDivide(a: number, b: number): Result<number, string> {
|
|
294
|
+
const res = divideNumbers(a, b).mapErr((err) => `Operation failed: ${err.message}`);
|
|
295
|
+
return res;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Example usage
|
|
299
|
+
console.log(safeDivide(10, 2)); // Result.Ok(5)
|
|
300
|
+
console.log(safeDivide(10, 0)); // Result.Err("Operation failed: Division by zero")
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### `mapOr`
|
|
304
|
+
|
|
305
|
+
Checks if the `Option` or `Result` is `Some` or `Ok`, and if so, applies the function to the value inside. If the `Option` or `Result` is `None` or `Err`, it returns the default value.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { Option } from "@carbonteq/fp";
|
|
309
|
+
|
|
310
|
+
// Simulated function to find a user by id
|
|
311
|
+
async function findUserById(id: number): Promise<Option<number>> {
|
|
312
|
+
// Simulate a database call that either returns a user or null
|
|
313
|
+
await Promise.resolve(id);
|
|
314
|
+
if (id === 0) {
|
|
315
|
+
return Option.None;
|
|
316
|
+
}
|
|
317
|
+
return Option.Some(id);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// A safe function that returns a string error message if the user is not found, instead of throwing an exception
|
|
321
|
+
async function safeFindUserById(id: number): Promise<Option<string>> {
|
|
322
|
+
const res = (await findUserById(id)).mapOr(`User not found`, (res) => `User: ${res}`);
|
|
323
|
+
return res;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Example usage
|
|
327
|
+
console.log(await safeFindUserById(10)); // Some(User: 10)
|
|
328
|
+
console.log(await safeFindUserById(0)); // Some(User not found)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
#### `tap`
|
|
332
|
+
|
|
333
|
+
`tap` is used to perform side effects on the `Result`/`Option` value without altering its contents. It is useful for logging, auditing, debugging complex chains of operations etc.
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
import { Result } from "@carbonteq/fp";
|
|
337
|
+
|
|
338
|
+
// Simulated database functions
|
|
339
|
+
async function findUserById(userId: number): Promise<Result<Record<string, number>, string>> {
|
|
340
|
+
// Simulate a database lookup
|
|
341
|
+
await Promise.resolve(userId);
|
|
342
|
+
if (userId === 0) {
|
|
343
|
+
return Result.Err("User not found");
|
|
344
|
+
}
|
|
345
|
+
return Result.Ok({ id: userId, balance: 100 });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function updateBalance(user: Record<string, number>, amount: number): Result<Record<string, number>, string> {
|
|
349
|
+
if (user.balance < amount) {
|
|
350
|
+
return Result.Err("Insufficient funds");
|
|
351
|
+
}
|
|
352
|
+
return Result.Ok({ ...user, balance: user.balance - amount });
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Process withdrawal with logging
|
|
356
|
+
const res = (await findUserById(1))
|
|
357
|
+
.tap((user) => console.log(`[Audit] User found: ${user.id}`))
|
|
358
|
+
.flatMap((user) => updateBalance(user, 10))
|
|
359
|
+
.tap((updated) => console.log(`[Transaction] New balance: $${updated.balance}`))
|
|
360
|
+
.mapErr((error) => console.error(`[Alert] Transaction failed: ${error}`));
|
|
361
|
+
|
|
362
|
+
console.log(res); // Result.Ok({ id: 1, balance: 90 })
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
#### `all`
|
|
366
|
+
|
|
367
|
+
`all` is used to combine an array of Results. If any errors exist they are accumulated, else the values are accumulated.
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
const combinedOk = Result.all(Result.Ok(1), Result.Ok(2), Result.Ok(3), Result.Ok(4));
|
|
371
|
+
console.log(combinedOk.unwrap()); // [1, 2, 3, 4]
|
|
372
|
+
const combinedErr = Result.all(Result.Err(1), Result.Err(2), Result.Err(3), Result.Err(4));
|
|
373
|
+
console.log(combinedErr.unwrapErr()); // [1, 2, 3, 4]
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
#### `validate`
|
|
377
|
+
|
|
378
|
+
Built on top of `all`, `validate` is used to execute an array of validator functions in parallel. If all validations pass, the original value is retained. If any validations fail, the errors are accumulated.
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { Result } from "@carbonteq/fp";
|
|
382
|
+
|
|
383
|
+
function isPositive(n: number) {
|
|
384
|
+
return n < 0 ? Result.Err(new Error("Input is negative")) : Result.Ok(true);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function isEven(n: number) {
|
|
388
|
+
return n % 2 !== 0 ? Result.Err(new Error("Input is odd")) : Result.Ok(true);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const validatedOk = Result.Ok(2).validate([isPositive, isEven]);
|
|
392
|
+
console.log(validatedOk.unwrap()); // 2
|
|
393
|
+
const validatedErr = Result.Ok(-3).validate([isPositive, isEven]);
|
|
394
|
+
console.log(validatedErr.unwrapErr()); // [Error("Input is negative"), Error("Input is odd")]
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
#### `unwrap`, `safeUnwrapErr`, `unwrapOr`, `unwrapOrElse`, `safeUnwrap`, and `unwrapErr`
|
|
398
|
+
|
|
399
|
+
These functions are used to extract the value from a `Result`. Note that **only `unwrap` and `safeUnwrap` are available for `Option`**.
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import { Result } from "@carbonteq/fp";
|
|
403
|
+
|
|
404
|
+
function divideNumbers(a: number, b: number): Result<number, Error> {
|
|
405
|
+
if (b === 0) {
|
|
406
|
+
return Result.Err(new Error("Division by zero"));
|
|
407
|
+
}
|
|
408
|
+
return Result.Ok(a / b);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Example usage of each function
|
|
412
|
+
let result = divideNumbers(10, 2);
|
|
413
|
+
console.log(result.unwrap()); // unwrap: 5 (Extracts the value from Result.Ok, throwing an error if it's Err.)
|
|
414
|
+
console.log(result.safeUnwrapErr()); // safeUnwrapErr: null (returns error if Err, null if Ok)
|
|
415
|
+
|
|
416
|
+
result = divideNumbers(10, 0);
|
|
417
|
+
console.log(result.unwrapOr(0)); // unwrapOr: 0 (Returns the contained value if Ok, or a default value if Err)
|
|
418
|
+
console.log(result.unwrapOrElse(() => 0)); // unwrapOrElse: 0 (Similar to unwrapOr, but the default value is generated by a function.)
|
|
419
|
+
console.log(result.safeUnwrap()); // safeUnwrap: null (Safely unwraps the value, returning null if it's an Err instead of throwing an error.)
|
|
420
|
+
|
|
421
|
+
const errorResult = Result.Err(new Error("Something went wrong"));
|
|
422
|
+
console.log(errorResult.unwrapErr()); // unwrapErr: Error: Something went wrong (Extracts the error from Result.Err, throwing an error if it's Ok)
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Build Your First Pipeline
|
|
426
|
+
|
|
427
|
+
Let's build a pipeline for processing an e-commerce order. This example demonstrates handling user input validation, inventory checks, and order processing.
|
|
428
|
+
|
|
429
|
+
#### Synchronous Pipeline
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
import { Result, matchRes } from "@carbonteq/fp";
|
|
433
|
+
|
|
434
|
+
interface Order {
|
|
435
|
+
productId: string;
|
|
436
|
+
quantity: number;
|
|
437
|
+
userId: string;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
interface ProcessedOrder {
|
|
441
|
+
orderId: string;
|
|
442
|
+
total: number;
|
|
443
|
+
status: "confirmed" | "failed";
|
|
444
|
+
order: Order;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Validate order input
|
|
448
|
+
function guardOrder(order: Order): Result<Order, string> {
|
|
449
|
+
if (!order.productId) return Result.Err("Product ID is required");
|
|
450
|
+
if (order.quantity <= 0) return Result.Err("Quantity must be positive");
|
|
451
|
+
if (!order.userId) return Result.Err("User ID is required");
|
|
452
|
+
return Result.Ok(order);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Check product availability
|
|
456
|
+
function guardInventoryCheck(order: Order): Result<Order, string> {
|
|
457
|
+
const availableStock = 100; // Simulated stock
|
|
458
|
+
return order.quantity <= availableStock ? Result.Ok(order) : Result.Err(`Insufficient stock. Available: ${availableStock}`);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Calculate order total
|
|
462
|
+
function calculateTotal(order: Order): Result<number, string> {
|
|
463
|
+
const price = 29.99; // Simulated price
|
|
464
|
+
return Result.Ok(order.quantity * price);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Process the order
|
|
468
|
+
function processOrder(order: Order): Result<ProcessedOrder, string> {
|
|
469
|
+
return Result.Ok(order)
|
|
470
|
+
.validate([guardOrder, guardInventoryCheck])
|
|
471
|
+
.flatZip(calculateTotal)
|
|
472
|
+
.map(([order, total]) => ({
|
|
473
|
+
orderId: `ORD-${Date.now()}`,
|
|
474
|
+
total: total,
|
|
475
|
+
status: "confirmed" as const,
|
|
476
|
+
order: order,
|
|
477
|
+
}))
|
|
478
|
+
.mapErr((error) => `Order processing failed: ${error}`);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Usage
|
|
482
|
+
const order: Order = {
|
|
483
|
+
productId: "PROD-123",
|
|
484
|
+
quantity: 2,
|
|
485
|
+
userId: "USER-456",
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const result = processOrder(order);
|
|
489
|
+
|
|
490
|
+
matchRes(result, {
|
|
491
|
+
Ok: (processedOrder) => {
|
|
492
|
+
console.log(`Order confirmed! Order ID: ${processedOrder.orderId}`);
|
|
493
|
+
console.log(`Total: $${processedOrder.total.toFixed(2)}`);
|
|
494
|
+
console.log(`Order: ${JSON.stringify(processedOrder.order)}`);
|
|
495
|
+
},
|
|
496
|
+
Err: (error) => {
|
|
497
|
+
console.error(`Error: ${error}`);
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Output:
|
|
502
|
+
// Order confirmed! Order ID: ORD-1716888600000
|
|
503
|
+
// Total: $59.98
|
|
504
|
+
// Order: {"productId":"PROD-123","quantity":2,"userId":"USER-456"}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
#### Asynchronous Pipeline
|
|
508
|
+
|
|
509
|
+
Let's build an asynchronous pipeline for a user registration system that includes credentials verification and profile setup.
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
import { Result, matchRes } from "@carbonteq/fp";
|
|
513
|
+
|
|
514
|
+
interface UserInput {
|
|
515
|
+
email: string;
|
|
516
|
+
password: string;
|
|
517
|
+
name: string;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
interface UserProfile {
|
|
521
|
+
userId: string;
|
|
522
|
+
email: string;
|
|
523
|
+
name: string;
|
|
524
|
+
verificationStatus: "pending" | "verified";
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Validate email format
|
|
528
|
+
async function guardEmail(email: string): Promise<Result<string, string>> {
|
|
529
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
530
|
+
return emailRegex.test(email) ? Result.Ok(email) : Result.Err("Invalid email format");
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Check if email is already registered
|
|
534
|
+
async function guardEmailAvailability(email: string): Promise<Result<string, string>> {
|
|
535
|
+
// Simulate database check
|
|
536
|
+
await Promise.resolve(email);
|
|
537
|
+
const registeredEmails = ["existing@example.com"];
|
|
538
|
+
return !registeredEmails.includes(email) ? Result.Ok(email) : Result.Err("Email already registered");
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Validate password strength
|
|
542
|
+
async function guardPassword(password: string): Promise<Result<string, string>> {
|
|
543
|
+
return password.length >= 8 ? Result.Ok(password) : Result.Err("Password must be at least 8 characters");
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Create user profile
|
|
547
|
+
async function createUserProfile(input: UserInput): Promise<Result<UserProfile, string>> {
|
|
548
|
+
const userProfile: UserProfile = {
|
|
549
|
+
userId: `USER-${Date.now()}`,
|
|
550
|
+
email: input.email,
|
|
551
|
+
name: input.name,
|
|
552
|
+
verificationStatus: "pending",
|
|
553
|
+
};
|
|
554
|
+
return Result.Ok(userProfile);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Send verification email
|
|
558
|
+
async function sendVerificationEmail(profile: UserProfile): Promise<Result<UserProfile, string>> {
|
|
559
|
+
// Simulate email sending and verification
|
|
560
|
+
await Promise.resolve(profile);
|
|
561
|
+
console.log(`Verification email sent to ${profile.email}`);
|
|
562
|
+
return Result.Ok(profile);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Main registration pipeline
|
|
566
|
+
async function registerUser(input: UserInput): Promise<Result<UserProfile, string | string[]>> {
|
|
567
|
+
const res = await Result.Ok(input)
|
|
568
|
+
.validate([({ email }) => guardEmail(email), ({ email }) => guardEmailAvailability(email), ({ password }) => guardPassword(password)])
|
|
569
|
+
.flatMap(createUserProfile)
|
|
570
|
+
.flatMap(sendVerificationEmail)
|
|
571
|
+
.toPromise();
|
|
572
|
+
|
|
573
|
+
return res;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Usage
|
|
577
|
+
async function main() {
|
|
578
|
+
const userInput: UserInput = {
|
|
579
|
+
email: "newuser@example.com",
|
|
580
|
+
password: "securepass123",
|
|
581
|
+
name: "John Doe",
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const result = await registerUser(userInput);
|
|
585
|
+
|
|
586
|
+
matchRes(result, {
|
|
587
|
+
Ok: (profile) => {
|
|
588
|
+
console.log(`Email: ${profile.email}`);
|
|
589
|
+
console.log("Registration successful!");
|
|
590
|
+
console.log(`User ID: ${profile.userId}`);
|
|
591
|
+
console.log(`Verification Status: ${profile.verificationStatus}`);
|
|
592
|
+
},
|
|
593
|
+
Err: (error) => {
|
|
594
|
+
console.error(`Registration failed: ${error}`);
|
|
595
|
+
},
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
main();
|
|
600
|
+
// Output:
|
|
601
|
+
// Verification email sent to newuser@example.com
|
|
602
|
+
// Email: newuser@example.com
|
|
603
|
+
// Registration successful!
|
|
604
|
+
// User ID: USER-1737921964102
|
|
605
|
+
// Verification Status: pending
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
## Contributing
|
|
609
|
+
|
|
610
|
+
Contributions are welcome! Feel free to open issues or submit pull requests.
|
package/package.json
CHANGED
|
@@ -1,74 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"engines": {
|
|
69
|
-
"node": ">=18.0.0",
|
|
70
|
-
"npm": ">=8.0.0",
|
|
71
|
-
"yarn": ">=1.22.0"
|
|
72
|
-
},
|
|
73
|
-
"packageManager": "yarn@1.22.19"
|
|
74
|
-
}
|
|
2
|
+
"name": "@carbonteq/fp",
|
|
3
|
+
"version": "0.8.0-alpha.0",
|
|
4
|
+
"description": "FP utils",
|
|
5
|
+
"author": "Arslan <rslnkrmt2552@gmail.com>",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.mjs",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
"node": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"/dist"
|
|
20
|
+
],
|
|
21
|
+
"scope": "@carbonteq",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/carbonteq/fp"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/carbonteq/fp/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/carbonteq/fp#readme",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@biomejs/biome": "^1.8.3",
|
|
37
|
+
"@changesets/cli": "^2.27.7",
|
|
38
|
+
"@microsoft/api-extractor": "^7.47.11",
|
|
39
|
+
"@swc/core": "^1.9.2",
|
|
40
|
+
"@tsconfig/node20": "^20.1.4",
|
|
41
|
+
"@types/node": "^20.14.9",
|
|
42
|
+
"changesets": "^1.0.2",
|
|
43
|
+
"jsr": "^0.13.2",
|
|
44
|
+
"tsup": "^8.3.5",
|
|
45
|
+
"tsx": "^4.19.2",
|
|
46
|
+
"typescript": "^5.5.3"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0",
|
|
50
|
+
"npm": ">=8.0.0",
|
|
51
|
+
"yarn": ">=1.22.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"lint": "biome check src tests",
|
|
55
|
+
"lint:fix": "biome check src tests --write --unsafe",
|
|
56
|
+
"fmt:dry": "biome format src tests",
|
|
57
|
+
"fmt": "biome format src tests --write",
|
|
58
|
+
"tc": "tsc --pretty --noEmit --project tsconfig.build.json",
|
|
59
|
+
"build": "NODE_ENV=production tsup",
|
|
60
|
+
"bd": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"test": "tsx --test tests/*.test.ts",
|
|
63
|
+
"test:dbg": "tsx --inspect-brk --test tests/*.test.ts",
|
|
64
|
+
"release": "changeset publish",
|
|
65
|
+
"tag": "changeset tag"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { Result, UnwrappedErrWithOk, UnwrappedOkWithErr } from "./result";
|
|
2
|
-
export type { CombineResults, UnitResult, UnwrapResult } from "./result";
|
|
3
|
-
export { Option, UnwrappedNone } from "./option";
|
|
4
|
-
export type { UnitOption, UnwrapOption } from "./option";
|
|
5
|
-
export { matchOpt, matchRes } from "./match";
|
|
6
|
-
export { UNIT } from "./unit";
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC1E,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var types=require("node:util/types");const UNIT=Symbol.for("UNIT");function _define_property$1(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}class UnwrappedErrWithOk extends Error{constructor(r){super(`Attempted to call unwrapErr on an okay value: <${r}>`)}}class UnwrappedOkWithErr extends Error{constructor(r){super(`Attempted to call unwrap on an Err value: <${r}>`)}}const preds=[el=>el.isOk(),el=>el.isErr()],Sentinel=Symbol.for("ResultSentinel");class Result{static Ok(val){return new Result(val,Sentinel)}static Err(err){return new Result(Sentinel,err)}isOk(){return this.val!==Sentinel}isErr(){return this.error!==Sentinel}isUnit(){return this.val===UNIT}toString(){return this.val!==Sentinel?`Result::Ok<${this.val}>`:`Result::Err<${this.error}>`}unwrap(){if(this.val===Sentinel){if(this.error instanceof Error)throw this.error;throw new UnwrappedOkWithErr(this)}return this.val}unwrapOr(def){return this.val===Sentinel?def:this.val}unwrapOrElse(def){return this.val===Sentinel?def():this.val}safeUnwrap(){return this.val===Sentinel?null:this.val}unwrapErr(){if(this.isOk())throw new UnwrappedErrWithOk(this);return this.error}safeUnwrapErr(){return this.error===Sentinel?null:this.error}map(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return types.isPromise(r)?r.then(val=>Result.Ok(val)):Result.Ok(r)}mapErr(fn){if(this.error!==Sentinel){let mappedErr=fn(this.error);return Result.Err(mappedErr)}return Result.Ok(this.val)}mapOr(default_,fn){return this.val===Sentinel?default_:fn(this.val)}mapOrAsync(default_,fn){return this.val===Sentinel?Promise.resolve(default_):fn(this.val)}and(r){return this.isErr()?this:r.isErr()?r:Result.Ok([this.val,r.val])}flatMap(fn){return this.val!==Sentinel?fn(this.val):Result.Err(this.error)}bind(fn){return this.val!==Sentinel?fn(this.val):Result.Err(this.error)}zipErr(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return types.isPromise(r)?r.then(result=>result.map(_=>this.val)):r.map(_=>this.val)}tap(fn){return this.val!==Sentinel&&fn(this.val),this}async tapAsync(fn){return this.val!==Sentinel&&await fn(this.val),this}zip(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return types.isPromise(r)?r.then(u=>Result.Ok([this.val,u])):Result.Ok([this.val,r])}flatZip(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return types.isPromise(r)?r.then(other=>other.map(u=>[this.val,u])):r.map(u=>[this.val,u])}static all(c,seq){let pred=preds[Number("ok"===c)];for(let el of seq)if(!pred(el))return!1;return!0}static any(c,seq){let pred=preds[Number("ok"===c)];for(let el of seq)if(pred(el))return!0;return!1}static sequence(...results){let vals=[];for(let r of results){if(r.isErr())return r;vals.push(r.unwrap())}return Result.Ok(vals)}static async lift(r){return r.isErr()?Promise.resolve(Result.Err(r.error)):r.val.then(v=>Result.Ok(v))}innerMap(mapper){if(this.val===Sentinel)return this;if(Array.isArray(this.val))return Result.Ok(this.val.map(mapper));throw Error("Can only be called for Result<Array<T>, E>")}pipe(...fns){let res=this;for(let fn of fns)res=res.map(fn);return res}constructor(val,error){_define_property$1(this,"val",void 0),_define_property$1(this,"error",void 0),this.val=val,this.error=error}}function _define_property(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}_define_property$1(Result,"UNIT_RESULT",new Result(UNIT,null));class UnwrappedNone extends Error{constructor(){super("Unwrapped Option<None>")}}const UNWRAPPED_NONE_ERR=new UnwrappedNone,NONE_VAL=Symbol.for("None");class Option{static Some(val){return new Option(val)}static fromNullable(val){return null===val?Option.None:Option.Some(val)}isSome(){return this.val!==NONE_VAL}isNone(){return this.val===NONE_VAL}isUnit(){return this.val===UNIT}unwrap(){if(this.val!==NONE_VAL)return this.val;throw UNWRAPPED_NONE_ERR}safeUnwrap(){return this.val!==NONE_VAL?this.val:null}toString(){return this.isNone()?"Option::None":`Option::Some(${this.val})`}map(fn){if(this.isNone())return Option.None;let val=fn(this.val);return types.isPromise(val)?val.then(u=>Option.Some(u)):Option.Some(val)}mapOr(def,fn){if(this.isNone())return Option.Some(def);let val=fn(this.val);return types.isPromise(val)?val.then(u=>Option.Some(u)):Option.Some(val)}flatMap(fn){return this.val!==NONE_VAL?fn(this.val):Option.None}bind(fn){return this.val!==NONE_VAL?fn(this.val):Option.None}and(opt){return this.val!==NONE_VAL&&opt.val!==NONE_VAL?Option.Some([this.val,opt.val]):Option.None}tap(fn){return this.val!==NONE_VAL&&fn(this.val),this}async tapAsync(fn){return this.val!==NONE_VAL&&await fn(this.val),this}zip(fn){if(this.val===NONE_VAL)return Option.None;let r=fn(this.val);return types.isPromise(r)?r.then(u=>Option.Some([this.val,u])):Option.Some([this.val,r])}flatZip(fn){if(this.val===NONE_VAL)return Option.None;let r=fn(this.val);return types.isPromise(r)?r.then(opt=>opt.map(u=>[this.val,u])):r.map(u=>[this.val,u])}static any(seq){for(let el of seq)if(el.val!==NONE_VAL)return!0;return!1}static all(seq){for(let el of seq)if(el.val===NONE_VAL)return!1;return!0}static sequence(...options){let vals=[];for(let opt of options){if(opt.val===NONE_VAL)return Option.None;vals.push(opt.val)}return Option.Some(vals)}static async lift(opt){return opt.isNone()?Promise.resolve(Option.None):opt.val.then(val=>Option.Some(val))}innerMap(mapper){if(this.val===NONE_VAL)return this;if(Array.isArray(this.val))return Option.Some(this.val.map(mapper));throw Error("Can only be called for Option<Array<T>>")}pipe(...fns){let x=this;for(let fn of fns)x=x.map(fn);return x}constructor(val){_define_property(this,"val",void 0),this.val=val}}_define_property(Option,"None",new Option(NONE_VAL)),_define_property(Option,"UNIT_OPT",new Option(UNIT)),exports.Option=Option,exports.Result=Result,exports.UNIT=UNIT,exports.UnwrappedErrWithOk=UnwrappedErrWithOk,exports.UnwrappedNone=UnwrappedNone,exports.UnwrappedOkWithErr=UnwrappedOkWithErr,exports.matchOpt=(o,branches)=>o.isSome()?branches.Some(o.unwrap()):branches.None(),exports.matchRes=(r,branches)=>r.isOk()?branches.Ok(r.unwrap()):branches.Err(r.unwrapErr());
|
package/lib/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isPromise}from"node:util/types";let UNIT=Symbol.for("UNIT");function _define_property$1(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}class UnwrappedErrWithOk extends Error{constructor(r){super(`Attempted to call unwrapErr on an okay value: <${r}>`)}}class UnwrappedOkWithErr extends Error{constructor(r){super(`Attempted to call unwrap on an Err value: <${r}>`)}}let preds=[el=>el.isOk(),el=>el.isErr()],Sentinel=Symbol.for("ResultSentinel");class Result{static Ok(val){return new Result(val,Sentinel)}static Err(err){return new Result(Sentinel,err)}isOk(){return this.val!==Sentinel}isErr(){return this.error!==Sentinel}isUnit(){return this.val===UNIT}toString(){return this.val!==Sentinel?`Result::Ok<${this.val}>`:`Result::Err<${this.error}>`}unwrap(){if(this.val===Sentinel){if(this.error instanceof Error)throw this.error;throw new UnwrappedOkWithErr(this)}return this.val}unwrapOr(def){return this.val===Sentinel?def:this.val}unwrapOrElse(def){return this.val===Sentinel?def():this.val}safeUnwrap(){return this.val===Sentinel?null:this.val}unwrapErr(){if(this.isOk())throw new UnwrappedErrWithOk(this);return this.error}safeUnwrapErr(){return this.error===Sentinel?null:this.error}map(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return isPromise(r)?r.then(val=>Result.Ok(val)):Result.Ok(r)}mapErr(fn){if(this.error!==Sentinel){let mappedErr=fn(this.error);return Result.Err(mappedErr)}return Result.Ok(this.val)}mapOr(default_,fn){return this.val===Sentinel?default_:fn(this.val)}mapOrAsync(default_,fn){return this.val===Sentinel?Promise.resolve(default_):fn(this.val)}and(r){return this.isErr()?this:r.isErr()?r:Result.Ok([this.val,r.val])}flatMap(fn){return this.val!==Sentinel?fn(this.val):Result.Err(this.error)}bind(fn){return this.val!==Sentinel?fn(this.val):Result.Err(this.error)}zipErr(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return isPromise(r)?r.then(result=>result.map(_=>this.val)):r.map(_=>this.val)}tap(fn){return this.val!==Sentinel&&fn(this.val),this}async tapAsync(fn){return this.val!==Sentinel&&await fn(this.val),this}zip(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return isPromise(r)?r.then(u=>Result.Ok([this.val,u])):Result.Ok([this.val,r])}flatZip(fn){if(this.val===Sentinel)return Result.Err(this.error);let r=fn(this.val);return isPromise(r)?r.then(other=>other.map(u=>[this.val,u])):r.map(u=>[this.val,u])}static all(c,seq){let pred=preds[Number("ok"===c)];for(let el of seq)if(!pred(el))return!1;return!0}static any(c,seq){let pred=preds[Number("ok"===c)];for(let el of seq)if(pred(el))return!0;return!1}static sequence(...results){let vals=[];for(let r of results){if(r.isErr())return r;vals.push(r.unwrap())}return Result.Ok(vals)}static async lift(r){return r.isErr()?Promise.resolve(Result.Err(r.error)):r.val.then(v=>Result.Ok(v))}innerMap(mapper){if(this.val===Sentinel)return this;if(Array.isArray(this.val))return Result.Ok(this.val.map(mapper));throw Error("Can only be called for Result<Array<T>, E>")}pipe(...fns){let res=this;for(let fn of fns)res=res.map(fn);return res}constructor(val,error){_define_property$1(this,"val",void 0),_define_property$1(this,"error",void 0),this.val=val,this.error=error}}function _define_property(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}_define_property$1(Result,"UNIT_RESULT",new Result(UNIT,null));class UnwrappedNone extends Error{constructor(){super("Unwrapped Option<None>")}}let UNWRAPPED_NONE_ERR=new UnwrappedNone,NONE_VAL=Symbol.for("None");class Option{static Some(val){return new Option(val)}static fromNullable(val){return null===val?Option.None:Option.Some(val)}isSome(){return this.val!==NONE_VAL}isNone(){return this.val===NONE_VAL}isUnit(){return this.val===UNIT}unwrap(){if(this.val!==NONE_VAL)return this.val;throw UNWRAPPED_NONE_ERR}safeUnwrap(){return this.val!==NONE_VAL?this.val:null}toString(){return this.isNone()?"Option::None":`Option::Some(${this.val})`}map(fn){if(this.isNone())return Option.None;let val=fn(this.val);return isPromise(val)?val.then(u=>Option.Some(u)):Option.Some(val)}mapOr(def,fn){if(this.isNone())return Option.Some(def);let val=fn(this.val);return isPromise(val)?val.then(u=>Option.Some(u)):Option.Some(val)}flatMap(fn){return this.val!==NONE_VAL?fn(this.val):Option.None}bind(fn){return this.val!==NONE_VAL?fn(this.val):Option.None}and(opt){return this.val!==NONE_VAL&&opt.val!==NONE_VAL?Option.Some([this.val,opt.val]):Option.None}tap(fn){return this.val!==NONE_VAL&&fn(this.val),this}async tapAsync(fn){return this.val!==NONE_VAL&&await fn(this.val),this}zip(fn){if(this.val===NONE_VAL)return Option.None;let r=fn(this.val);return isPromise(r)?r.then(u=>Option.Some([this.val,u])):Option.Some([this.val,r])}flatZip(fn){if(this.val===NONE_VAL)return Option.None;let r=fn(this.val);return isPromise(r)?r.then(opt=>opt.map(u=>[this.val,u])):r.map(u=>[this.val,u])}static any(seq){for(let el of seq)if(el.val!==NONE_VAL)return!0;return!1}static all(seq){for(let el of seq)if(el.val===NONE_VAL)return!1;return!0}static sequence(...options){let vals=[];for(let opt of options){if(opt.val===NONE_VAL)return Option.None;vals.push(opt.val)}return Option.Some(vals)}static async lift(opt){return opt.isNone()?Promise.resolve(Option.None):opt.val.then(val=>Option.Some(val))}innerMap(mapper){if(this.val===NONE_VAL)return this;if(Array.isArray(this.val))return Option.Some(this.val.map(mapper));throw Error("Can only be called for Option<Array<T>>")}pipe(...fns){let x=this;for(let fn of fns)x=x.map(fn);return x}constructor(val){_define_property(this,"val",void 0),this.val=val}}_define_property(Option,"None",new Option(NONE_VAL)),_define_property(Option,"UNIT_OPT",new Option(UNIT));let matchRes=(r,branches)=>r.isOk()?branches.Ok(r.unwrap()):branches.Err(r.unwrapErr()),matchOpt=(o,branches)=>o.isSome()?branches.Some(o.unwrap()):branches.None();export{Option,Result,UNIT,UnwrappedErrWithOk,UnwrappedNone,UnwrappedOkWithErr,matchOpt,matchRes};
|
package/lib/match.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Option } from "./option";
|
|
2
|
-
import type { Result } from "./result";
|
|
3
|
-
export declare const matchRes: <T, E, U>(r: Result<T, E>, branches: {
|
|
4
|
-
Ok: (val: T) => U;
|
|
5
|
-
Err: (err: E) => U;
|
|
6
|
-
}) => U;
|
|
7
|
-
export declare const matchOpt: <T, U>(o: Option<T>, branches: {
|
|
8
|
-
Some: (val: T) => U;
|
|
9
|
-
None: () => U;
|
|
10
|
-
}) => U;
|
|
11
|
-
//# sourceMappingURL=match.d.ts.map
|
package/lib/match.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,KAC5B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,YACL;IAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;CAAE,KACjD,CAKF,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,KACzB,MAAM,CAAC,CAAC,CAAC,YACF;IAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,CAAA;CAAE,KAC9C,CAKF,CAAC"}
|
package/lib/option.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { UNIT } from "./unit";
|
|
2
|
-
type InnerMapMapper<T, U> = T extends Array<infer Inner> ? (val: Inner) => U : never;
|
|
3
|
-
type InnerMapReturn<T, U> = T extends Array<unknown> ? Option<Array<U>> : never;
|
|
4
|
-
export declare class UnwrappedNone extends Error {
|
|
5
|
-
constructor();
|
|
6
|
-
}
|
|
7
|
-
export type UnitOption = Option<UNIT>;
|
|
8
|
-
export type UnwrapOption<T> = T extends Option<infer R> ? R : never;
|
|
9
|
-
type CombinedOptions<T extends Option<unknown>[]> = {
|
|
10
|
-
[K in keyof T]: UnwrapOption<T[K]>;
|
|
11
|
-
};
|
|
12
|
-
export declare class Option<T> {
|
|
13
|
-
readonly val: T;
|
|
14
|
-
private constructor();
|
|
15
|
-
static readonly None: Option<never>;
|
|
16
|
-
static readonly UNIT_OPT: UnitOption;
|
|
17
|
-
static Some<Inner>(val: Inner): Option<Inner>;
|
|
18
|
-
static fromNullable<T>(val: T): Option<NonNullable<T>>;
|
|
19
|
-
isSome(): this is Option<T>;
|
|
20
|
-
isNone(): this is Option<never>;
|
|
21
|
-
isUnit(): this is Option<UNIT>;
|
|
22
|
-
unwrap(): T;
|
|
23
|
-
safeUnwrap(): T | null;
|
|
24
|
-
toString(): string;
|
|
25
|
-
map<U>(fn: (val: T) => U): Option<U>;
|
|
26
|
-
map<U>(fn: (val: T) => Promise<U>): Promise<Option<U>>;
|
|
27
|
-
mapOr<U>(def: U, fn: (val: T) => U): Option<U>;
|
|
28
|
-
mapOr<U>(def: U, fn: (val: T) => Promise<U>): Promise<Option<U>>;
|
|
29
|
-
flatMap<U>(fn: (val: T) => Option<U>): Option<U>;
|
|
30
|
-
flatMap<U>(fn: (val: T) => Promise<Option<U>>): Promise<Option<U>>;
|
|
31
|
-
bind<U>(fn: (val: T) => Option<U>): Option<U>;
|
|
32
|
-
bind<U>(fn: (val: T) => Promise<Option<U>>): Promise<Option<U>>;
|
|
33
|
-
and<U>(opt: Option<U>): Option<[T, U]>;
|
|
34
|
-
tap(fn: (val: T) => void): Option<T>;
|
|
35
|
-
tapAsync(fn: (val: T) => Promise<unknown>): Promise<Option<T>>;
|
|
36
|
-
zip<U>(fn: (val: T) => Promise<U>): Promise<Option<[T, U]>>;
|
|
37
|
-
zip<U>(fn: (val: T) => U): Option<[T, U]>;
|
|
38
|
-
flatZip<U>(fn: (val: T) => Promise<Option<U>>): Promise<Option<[T, U]>>;
|
|
39
|
-
flatZip<U>(fn: (val: T) => Option<U>): Option<[T, U]>;
|
|
40
|
-
static any<T>(seq: Option<T>[]): boolean;
|
|
41
|
-
static all<T>(seq: Option<T>[]): boolean;
|
|
42
|
-
static sequence<T extends Option<unknown>[]>(...options: T): Option<CombinedOptions<T>>;
|
|
43
|
-
static lift<T>(opt: Option<Promise<T>>): Promise<Option<T>>;
|
|
44
|
-
innerMap<U>(mapper: InnerMapMapper<T, U>): InnerMapReturn<T, U>;
|
|
45
|
-
pipe<U>(fn: (val: T) => U): Option<U>;
|
|
46
|
-
pipe<U, V>(fn: (val: T) => U, fn2: (val: U) => V): Option<V>;
|
|
47
|
-
pipe<U, V, W>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W): Option<W>;
|
|
48
|
-
pipe<U, V, W, X>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X): Option<X>;
|
|
49
|
-
pipe<U, V, W, X, Y>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y): Option<Y>;
|
|
50
|
-
pipe<U, V, W, X, Y, Z>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z): Option<Z>;
|
|
51
|
-
pipe<U, V, W, X, Y, Z, A>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A): Option<A>;
|
|
52
|
-
pipe<U, V, W, X, Y, Z, A, B>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B): Option<B>;
|
|
53
|
-
pipe<U, V, W, X, Y, Z, A, B, C>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B, fn9: (val: B) => C): Option<C>;
|
|
54
|
-
pipe<U, V, W, X, Y, Z, A, B, C, D>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B, fn9: (val: B) => C, fn10: (val: C) => D): Option<D>;
|
|
55
|
-
}
|
|
56
|
-
export {};
|
|
57
|
-
//# sourceMappingURL=option.d.ts.map
|
package/lib/option.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings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,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAChB,MAAM,CAAC,CAAC,CAAC;IACZ,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EACjB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GACjB,MAAM,CAAC,CAAC,CAAC;CASZ"}
|
package/lib/result.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { UNIT } from "./unit";
|
|
2
|
-
export declare class UnwrappedErrWithOk extends Error {
|
|
3
|
-
constructor(r: Result<unknown, unknown>);
|
|
4
|
-
}
|
|
5
|
-
export declare class UnwrappedOkWithErr extends Error {
|
|
6
|
-
constructor(r: Result<unknown, unknown>);
|
|
7
|
-
}
|
|
8
|
-
export type UnitResult<E = never> = Result<UNIT, E>;
|
|
9
|
-
type Mapper<T, U> = (val: T) => U;
|
|
10
|
-
type AsyncMapper<T, U> = (val: T) => Promise<U>;
|
|
11
|
-
type OkOrErr = "ok" | "err";
|
|
12
|
-
export type UnwrapResult<T extends Result<unknown, unknown>> = T extends Result<infer U, infer E> ? {
|
|
13
|
-
ok: U;
|
|
14
|
-
err: E;
|
|
15
|
-
} : never;
|
|
16
|
-
type CombinedResultOk<T extends Result<unknown, unknown>[]> = {
|
|
17
|
-
[K in keyof T]: UnwrapResult<T[K]>["ok"];
|
|
18
|
-
};
|
|
19
|
-
type CombinedResultErr<T extends Result<unknown, unknown>[]> = {
|
|
20
|
-
[K in keyof T]: UnwrapResult<T[K]>["err"];
|
|
21
|
-
}[number];
|
|
22
|
-
export type CombineResults<T extends Result<unknown, unknown>[]> = Result<CombinedResultOk<T>, CombinedResultErr<T>>;
|
|
23
|
-
type InnerMapMapper<T, U> = T extends Array<infer Inner> ? (val: Inner) => U : never;
|
|
24
|
-
type InnerMapReturn<T, E, U> = T extends Array<unknown> ? Result<Array<U>, E> : never;
|
|
25
|
-
/** Sentinel value */
|
|
26
|
-
declare const Sentinel: unique symbol;
|
|
27
|
-
type Sentinel = typeof Sentinel;
|
|
28
|
-
export declare class Result<T, E> {
|
|
29
|
-
private readonly val;
|
|
30
|
-
private readonly error;
|
|
31
|
-
static readonly UNIT_RESULT: UnitResult;
|
|
32
|
-
protected constructor(val: T | Sentinel, error: E | Sentinel);
|
|
33
|
-
static Ok<T, E = never>(val: T): Result<T, E>;
|
|
34
|
-
static Err<E, T = never>(err: E): Result<T, E>;
|
|
35
|
-
isOk(): this is Result<T, never>;
|
|
36
|
-
isErr(): this is Result<never, E>;
|
|
37
|
-
isUnit(): this is Result<UNIT, never>;
|
|
38
|
-
toString(): string;
|
|
39
|
-
unwrap(): T;
|
|
40
|
-
unwrapOr(def: T): T;
|
|
41
|
-
unwrapOrElse(def: () => T): T;
|
|
42
|
-
unwrapOrElse(def: () => Promise<T>): Promise<T>;
|
|
43
|
-
safeUnwrap(): T | null;
|
|
44
|
-
unwrapErr(): E;
|
|
45
|
-
safeUnwrapErr(): E | null;
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param {Mapper<T, U>} fn The mapping/endofunctor to apply to the internal Ok value (T -> U)
|
|
49
|
-
* @returns Result<U, E> containing the mapped value
|
|
50
|
-
* @example
|
|
51
|
-
* const r = Result.Ok({data: 42})
|
|
52
|
-
* const r2 = Result.Err(new Error("something went wrong"))
|
|
53
|
-
* const mapper = (d: {data: 42}) => d.data * 2
|
|
54
|
-
* const result1 = r.map(mapper) // Result containing 64 as the ok value
|
|
55
|
-
* const result2 = r2.map(mapper) // mapper won't be applied, as r2 was in error state
|
|
56
|
-
*/
|
|
57
|
-
map<U>(fn: (val: T) => Promise<U>): Promise<Result<U, E>>;
|
|
58
|
-
map<U>(fn: (val: T) => U): Result<U, E>;
|
|
59
|
-
/** Same as map, but for the error value instead of the Ok value */
|
|
60
|
-
mapErr<U>(fn: Mapper<E, U>): Result<T, U>;
|
|
61
|
-
mapOr<U>(default_: U, fn: Mapper<T, U>): U;
|
|
62
|
-
mapOrAsync<U>(default_: U, fn: AsyncMapper<T, U>): Promise<U>;
|
|
63
|
-
/** For combining two results. For the lazy eval version, see {@link flatZip} and {@link zipAsync} */
|
|
64
|
-
and<U, E2>(r: Result<U, E2>): Result<[T, U], E | E2>;
|
|
65
|
-
/**
|
|
66
|
-
* Also known as `andThen`, `bind` or `fmap`
|
|
67
|
-
* Like Result.map but used in cases where the mapper func returns a Result instead of a containable value
|
|
68
|
-
* @example
|
|
69
|
-
* const r: Result<string, SomeError> = Result.Ok("42")
|
|
70
|
-
* const mapper = (d: string) => {
|
|
71
|
-
* const n = Number.parseInt(d)
|
|
72
|
-
* if(Number.isNumber(n) && !Number.isNaN(n)) return Result.Ok(n)
|
|
73
|
-
*
|
|
74
|
-
* return Result.Err(new InvalidNumStringError(d))
|
|
75
|
-
* }
|
|
76
|
-
* const result1 = r.map(mapper) // Type is Result<Result<number, InvalidNumStringError>, SomeError>
|
|
77
|
-
* const result2 = r.flatMap(mapper) // Type is Result<number, SomeError | InvalidNumStringError>
|
|
78
|
-
*/
|
|
79
|
-
flatMap<U, E2>(fn: (val: T) => Promise<Result<U, E | E2>>): Promise<Result<U, E | E2>>;
|
|
80
|
-
flatMap<U, E2>(fn: (val: T) => Result<U, E2>): Result<U, E | E2>;
|
|
81
|
-
/**
|
|
82
|
-
* Also known as `andThen`, `fmap` or `flatMap`
|
|
83
|
-
* Like Result.map but used in cases where the mapper func returns a Result instead of a containable value
|
|
84
|
-
* @example
|
|
85
|
-
* const r: Result<string, SomeError> = Result.Ok("42")
|
|
86
|
-
* const mapper = (d: string) => {
|
|
87
|
-
* const n = Number.parseInt(d)
|
|
88
|
-
* if(Number.isNumber(n) && !Number.isNaN(n)) return Result.Ok(n)
|
|
89
|
-
*
|
|
90
|
-
* return Result.Err(new InvalidNumStringError(d))
|
|
91
|
-
* }
|
|
92
|
-
* const result1 = r.map(mapper) // Type is Result<Result<number, InvalidNumStringError>, SomeError>
|
|
93
|
-
* const result2 = r.bind(mapper) // Type is Result<number, SomeError | InvalidNumStringError>
|
|
94
|
-
*/
|
|
95
|
-
bind<U, E2>(fn: (val: T) => Promise<Result<U, E | E2>>): Promise<Result<U, E | E2>>;
|
|
96
|
-
bind<U, E2>(fn: (val: T) => Result<U, E2>): Result<U, E | E2>;
|
|
97
|
-
/**
|
|
98
|
-
* For combining the errors only while retaining the original value.
|
|
99
|
-
* @example
|
|
100
|
-
* const r: Result<string, SomeError> = Result.Ok('42')
|
|
101
|
-
* const binderOk = (d: string) => Result.Ok<number, SomeOtherError>(0909)
|
|
102
|
-
* const binderErr = (d: string) => Result.Err<number, SomeOtherError>(new SomeOtherError())
|
|
103
|
-
*
|
|
104
|
-
* const res1 = r.zipErr(binderOk) // Result<string, SomeError | SomeOtherError> - Value: Result.Ok('42') - No change in Ok type
|
|
105
|
-
* const res2 = r.zipErr(binderErr) // Result<string, SomeError | SomeOtherError> - Value: Result.Err(new SomeOtherError())
|
|
106
|
-
*/
|
|
107
|
-
zipErr<E2>(fn: (val: T) => Promise<Result<unknown, E2>>): Promise<Result<T, E | E2>>;
|
|
108
|
-
zipErr<E2>(fn: (val: T) => Result<unknown, E2>): Result<T, E | E2>;
|
|
109
|
-
/** For running infallible side-effects on the contained value. Up to the programmer to ensure the underlying function doesn't fail */
|
|
110
|
-
tap(fn: (val: T) => void): Result<T, E>;
|
|
111
|
-
/**
|
|
112
|
-
* Async version of {@link tap}
|
|
113
|
-
* @see {@link tap}
|
|
114
|
-
*/
|
|
115
|
-
tapAsync(fn: (val: T) => Promise<void>): Promise<Result<T, E>>;
|
|
116
|
-
zip<U>(fn: (val: T) => Promise<U>): Promise<Result<[T, U], E>>;
|
|
117
|
-
zip<U>(fn: (val: T) => U): Result<[T, U], E>;
|
|
118
|
-
/** For combining two results lazily. For the eager eval version, see {@link and} */
|
|
119
|
-
flatZip<U, E2>(fn: (val: T) => Promise<Result<U, E2>>): Promise<Result<[T, U], E | E2>>;
|
|
120
|
-
flatZip<U, E2>(fn: (val: T) => Result<U, E2>): Result<[T, U], E | E2>;
|
|
121
|
-
/** Type guard specifying all array results as Ok/Err */
|
|
122
|
-
static all<T, E extends Error>(c: "ok", seq: Result<T, E>[]): seq is Result<T, never>[];
|
|
123
|
-
static all<T, E extends Error>(c: "err", seq: Result<T, E>[]): seq is Result<never, E>[];
|
|
124
|
-
/** Whether any of the underlying results are Ok or Err */
|
|
125
|
-
static any<T, E extends Error>(c: OkOrErr, seq: Result<T, E>[]): boolean;
|
|
126
|
-
/**
|
|
127
|
-
* `Result.sequence(Result<T1, E1>, Result<T2, E2>, ...)` will return `Result<[T1, T2, ...], E1 | E2 | ...>`
|
|
128
|
-
* @example
|
|
129
|
-
* const r1 = Result.Ok<string, string>("abc")
|
|
130
|
-
* const r2 = Result.Ok<number, Error>(123)
|
|
131
|
-
* const r = Result.sequence(r1, r2) // r will be of type Result<[string, number], string | Error>
|
|
132
|
-
*/
|
|
133
|
-
static sequence<T extends Result<unknown, unknown>[]>(...results: T): Result<CombinedResultOk<T>, CombinedResultErr<T>>;
|
|
134
|
-
/** Convert a Result of a Promise to the Promise of a Result */
|
|
135
|
-
static lift<T, E extends Error>(r: Result<Promise<T>, E>): Promise<Result<T, E>>;
|
|
136
|
-
innerMap<U>(mapper: InnerMapMapper<T, U>): InnerMapReturn<T, E, U>;
|
|
137
|
-
pipe<U>(fn: (val: T) => U): Result<U, E>;
|
|
138
|
-
pipe<U, V>(fn: (val: T) => U, fn2: (val: U) => V): Result<V, E>;
|
|
139
|
-
pipe<U, V, W>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W): Result<W, E>;
|
|
140
|
-
pipe<U, V, W, X>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X): Result<X, E>;
|
|
141
|
-
pipe<U, V, W, X, Y>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y): Result<Y, E>;
|
|
142
|
-
pipe<U, V, W, X, Y, Z>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z): Result<Z, E>;
|
|
143
|
-
pipe<U, V, W, X, Y, Z, A>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A): Result<A, E>;
|
|
144
|
-
pipe<U, V, W, X, Y, Z, A, B>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B): Result<B, E>;
|
|
145
|
-
pipe<U, V, W, X, Y, Z, A, B, C>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B, fn9: (val: B) => C): Result<C, E>;
|
|
146
|
-
pipe<U, V, W, X, Y, Z, A, B, C, D>(fn: (val: T) => U, fn2: (val: U) => V, fn3: (val: V) => W, fn4: (val: W) => X, fn5: (val: X) => Y, fn6: (val: Y) => Z, fn7: (val: Z) => A, fn8: (val: A) => B, fn9: (val: B) => C, fn10: (val: C) => D): Result<D, E>;
|
|
147
|
-
}
|
|
148
|
-
export {};
|
|
149
|
-
//# sourceMappingURL=result.d.ts.map
|
package/lib/result.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;CAGvC;AAED,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;CAGvC;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAEpD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAClC,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAIhD,KAAK,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC;AAK5B,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,MAAM,CAC9E,MAAM,CAAC,EACP,MAAM,CAAC,CACP,GACE;IAAE,EAAE,EAAE,CAAC,CAAC;IAAC,GAAG,EAAE,CAAC,CAAA;CAAE,GACjB,KAAK,CAAC;AAET,KAAK,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,OAAO,EAAE,OAAO,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CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EACjB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAClB,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GACjB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;CASf"}
|
package/lib/tuple.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const TUPLE_KEY: unique symbol;
|
|
2
|
-
export interface Tuple<Inner> extends Array<Inner> {
|
|
3
|
-
[TUPLE_KEY]: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare const setAsTuple: <Inner, T extends Array<Inner>>(arr: T) => Tuple<Inner>;
|
|
6
|
-
export declare const isTuple: <Inner>(t: unknown) => t is Tuple<Inner>;
|
|
7
|
-
export type AppendToTuple<T, U> = T extends [...infer Rest, infer L] ? [...Rest, L, U] : [T, U];
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=tuple.d.ts.map
|
package/lib/tuple.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,SAAS,eAAsB,CAAC;AAEtC,MAAM,WAAW,KAAK,CAAC,KAAK,CAAE,SAAQ,KAAK,CAAC,KAAK,CAAC;IACjD,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,GAAI,KAAK,EAAE,CAAC,SAAS,KAAK,CAAC,KAAK,CAAC,OAClD,CAAC,KACJ,KAAK,CAAC,KAAK,CAOb,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,KAAK,KAAK,OAAO,KAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAEhC,CAAC;AAE7B,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,MAAM,CAAC,CAAC,GACjE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,GACf,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
package/lib/unit.d.ts
DELETED
package/lib/unit.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../src/unit.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,eAAqB,CAAC;AACvC,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC"}
|