@@ -539,7 +539,7 @@ Note that in the above example if `parseHeaders` returns an `Err` then `.map` an
539
539
#### ` Result.andTee ` (method)
540
540
541
541
Takes a ` Result<T, E> ` and lets the original ` Result<T, E> ` pass through regardless the result of the passed-in function.
542
- This is a handy way to handle side effects whose failure or success should not affect your main logics such as logging.
542
+ This is a handy way to handle side effects whose failure or success should not affect your main logics such as logging.
543
543
544
544
** Signature:**
545
545
@@ -560,7 +560,7 @@ import { insertUser } from 'imaginary-database'
560
560
561
561
// ^ assume parseUserInput, logUser and insertUser have the following signatures:
562
562
// parseUserInput(input: RequestData): Result<User, ParseError>
563
- // logUser(user: User): Result<void, LogError>
563
+ // logUser(user: User): Result<void, LogError>
564
564
// insertUser(user: User): ResultAsync<void, InsertError>
565
565
// Note logUser returns void upon success but insertUser takes User type.
566
566
@@ -579,7 +579,7 @@ resAsync.then((res: Result<void, ParseError | InsertError>) => {e
579
579
}))
580
580
```
581
581
582
- [ ⬆️ Back to top] ( #toc )
582
+ [ ⬆️ Back to top] ( #toc )
583
583
584
584
---
585
585
@@ -610,7 +610,7 @@ import { insertUser } from 'imaginary-database'
610
610
// parseUserInput(input: RequestData): Result<User, ParseError>
611
611
// validateUser(user: User): Result<void, ValidateError>
612
612
// insertUser(user: User): ResultAsync<void, InsertError>
613
- // Note validateUser returns void upon success but insertUser takes User type.
613
+ // Note validateUser returns void upon success but insertUser takes User type.
614
614
615
615
const resAsync = parseUserInput (userInput )
616
616
.andThrough (validateUser )
@@ -625,14 +625,14 @@ resAsync.then((res: Result<void, ParseErro | ValidateError | InsertError>) => {e
625
625
}
626
626
}))
627
627
```
628
-
629
- [ ⬆️ Back to top] ( #toc )
628
+
629
+ [ ⬆️ Back to top] ( #toc )
630
630
631
631
---
632
632
633
633
#### ` Result.asyncAndThrough ` (method)
634
634
635
- Similar to ` andThrough ` except you must return a ResultAsync.
635
+ Similar to ` andThrough ` except you must return a ResultAsync.
636
636
637
637
You can then chain the result of ` asyncAndThrough ` using the ` ResultAsync ` apis (like ` map ` , ` mapErr ` , ` andThen ` , etc.)
638
638
@@ -647,7 +647,7 @@ import { sendNotification } from 'imaginary-service'
647
647
// parseUserInput(input: RequestData): Result<User, ParseError>
648
648
// insertUser(user: User): ResultAsync<void, InsertError>
649
649
// sendNotification(user: User): ResultAsync<void, NotificationError>
650
- // Note insertUser returns void upon success but sendNotification takes User type.
650
+ // Note insertUser returns void upon success but sendNotification takes User type.
651
651
652
652
const resAsync = parseUserInput (userInput )
653
653
.asyncAndThrough (insertUser )
@@ -662,10 +662,11 @@ resAsync.then((res: Result<void, ParseError | InsertError | NotificationError>)
662
662
}
663
663
}))
664
664
```
665
-
666
- [ ⬆️ Back to top] ( #toc )
665
+
666
+ [ ⬆️ Back to top] ( #toc )
667
667
668
668
---
669
+
669
670
#### ` Result.fromThrowable ` (static class method)
670
671
671
672
> Although Result is not an actual JS class, the way that ` fromThrowable ` has been implemented requires that you call ` fromThrowable ` as though it were a static method on ` Result ` . See examples below.
@@ -1205,11 +1206,12 @@ const resultMessage = await validateUser(user)
1205
1206
[ ⬆️ Back to top] ( #toc )
1206
1207
1207
1208
---
1209
+
1208
1210
#### ` ResultAsync.andTee ` (method)
1209
1211
1210
- Takes a ` ResultAsync<T, E> ` and lets the original ` ResultAsync<T, E> ` pass through regardless
1212
+ Takes a ` ResultAsync<T, E> ` and lets the original ` ResultAsync<T, E> ` pass through regardless
1211
1213
the result of the passed-in function.
1212
- This is a handy way to handle side effects whose failure or success should not affect your main logics such as logging.
1214
+ This is a handy way to handle side effects whose failure or success should not affect your main logics such as logging.
1213
1215
1214
1216
** Signature:**
1215
1217
@@ -1232,28 +1234,28 @@ import { sendNotification } from 'imaginary-service'
1232
1234
// insertUser(user: User): ResultAsync<User, InsertError>
1233
1235
// logUser(user: User): Result<void, LogError>
1234
1236
// sendNotification(user: User): ResultAsync<void, NotificationError>
1235
- // Note logUser returns void on success but sendNotification takes User type.
1237
+ // Note logUser returns void on success but sendNotification takes User type.
1236
1238
1237
1239
const resAsync = insertUser (user )
1238
1240
.andTee (logUser )
1239
1241
.andThen (sendNotification )
1240
1242
1241
- // Note there is no LogError in the types below
1243
+ // Note there is no LogError in the types below
1242
1244
resAsync .then ((res : Result <void , InsertError | NotificationError >) => {e
1243
1245
if (res .isErr ()){
1244
1246
console .log (" Oops, at least one step failed" , res .error )
1245
1247
}
1246
1248
else {
1247
1249
console .log (" User has been inserted and notified successfully." )
1248
1250
}
1249
- }))
1251
+ }))
1250
1252
```
1251
1253
1252
- [ ⬆️ Back to top] ( #toc )
1254
+ [ ⬆️ Back to top] ( #toc )
1253
1255
1254
1256
---
1255
- #### ` ResultAsync.andThrough ` (method)
1256
1257
1258
+ #### ` ResultAsync.andThrough ` (method)
1257
1259
1258
1260
Similar to ` andTee ` except for:
1259
1261
@@ -1281,7 +1283,7 @@ import { sendNotification } from 'imaginary-service'
1281
1283
// buildUser(userRaw: UserRaw): ResultAsync<User, BuildError>
1282
1284
// insertUser(user: User): ResultAsync<void, InsertError>
1283
1285
// sendNotification(user: User): ResultAsync<void, NotificationError>
1284
- // Note insertUser returns void upon success but sendNotification takes User type.
1286
+ // Note insertUser returns void upon success but sendNotification takes User type.
1285
1287
1286
1288
const resAsync = buildUser (userRaw )
1287
1289
.andThrough (insertUser )
@@ -1294,12 +1296,13 @@ resAsync.then((res: Result<void, BuildError | InsertError | NotificationError>)
1294
1296
else {
1295
1297
console .log (" User data has been built, inserted and notified successfully." )
1296
1298
}
1297
- }))
1299
+ }))
1298
1300
```
1299
1301
1300
- [ ⬆️ Back to top] ( #toc )
1302
+ [ ⬆️ Back to top] ( #toc )
1301
1303
1302
1304
---
1305
+
1303
1306
#### ` ResultAsync.combine ` (static class method)
1304
1307
1305
1308
Combine lists of ` ResultAsync ` s.
0 commit comments