Skip to content

Commit 42f68a8

Browse files
Fix result example tests
1 parent 92b4243 commit 42f68a8

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

packages/@rescript/runtime/Stdlib_Result.resi

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,16 @@ When `res` is `Error`, returns the error unchanged.
330330
## Examples
331331
332332
```rescript
333-
let asyncSquare = async x => x * x
333+
let square = x => x * x
334334
335-
let result1 = Result.mapOkAsync(Promise.resolve(Ok(4)), asyncSquare) // Returns promise that resolves to Ok(16)
336-
let result2 = Result.mapOkAsync(Promise.resolve(Error("invalid")), asyncSquare) // Returns promise that resolves to Error("invalid")
335+
let result1 = await Result.mapOkAsync(Promise.resolve(Ok(4)), square)
336+
result1 == Ok(16)
337+
338+
let result2 = await Result.mapOkAsync(
339+
Promise.resolve(Error("invalid")),
340+
square,
341+
)
342+
result2 == Error("invalid")
337343
```
338344
*/
339345
let mapOkAsync: (
@@ -349,10 +355,13 @@ When `res` is `Ok`, returns the ok value unchanged.
349355
## Examples
350356
351357
```rescript
352-
let asyncFormatError = async e => `Error: ${e}`
358+
let formatError = e => `Error: ${e}`
353359
354-
let result1 = Result.mapErrorAsync(Promise.resolve(Ok(42)), asyncFormatError) // Returns promise that resolves to Ok(42)
355-
let result2 = Result.mapErrorAsync(Promise.resolve(Error("invalid")), asyncFormatError) // Returns promise that resolves to Error("Error: invalid")
360+
let result1 = await Result.mapErrorAsync(Promise.resolve(Ok(42)), formatError)
361+
result1 == Ok(42)
362+
363+
let result2 = await Result.mapErrorAsync(Promise.resolve(Error("invalid")), formatError)
364+
result2 == Error("Error: invalid")
356365
```
357366
*/
358367
let mapErrorAsync: (
@@ -368,15 +377,21 @@ When `res` is `Error`, returns the error unchanged.
368377
## Examples
369378
370379
```rescript
371-
let asyncValidate = async x =>
380+
let asyncValidate = async x =>
372381
if x > 0 {
373382
Ok(x * 2)
374383
} else {
375384
Error("Must be positive")
376385
}
377386
378-
let result1 = Result.flatMapOkAsync(Promise.resolve(Ok(5)), asyncValidate) // Returns promise that resolves to Ok(10)
379-
let result2 = Result.flatMapOkAsync(Promise.resolve(Error("Already failed")), asyncValidate) // Returns promise that resolves to Error("Already failed")
387+
let result1 = await Result.flatMapOkAsync(Promise.resolve(Ok(5)), asyncValidate)
388+
result1 == Ok(10)
389+
390+
let result2 = await Result.flatMapOkAsync(
391+
Promise.resolve(Error("Already failed")),
392+
asyncValidate,
393+
)
394+
result2 == Error("Already failed")
380395
```
381396
*/
382397
let flatMapOkAsync: (
@@ -392,15 +407,24 @@ When `res` is `Ok`, returns the ok value unchanged.
392407
## Examples
393408
394409
```rescript
395-
let asyncRecover = async error =>
410+
let asyncRecover = async error =>
396411
if error === "timeout" {
397412
Ok("default")
398413
} else {
399414
Error(error)
400415
}
401416
402-
let result1 = Result.flatMapErrorAsync(Promise.resolve(Error("timeout")), asyncRecover) // Returns promise that resolves to Ok("default")
403-
let result2 = Result.flatMapErrorAsync(Promise.resolve(Ok("default")), asyncRecover) // Returns promise that resolves to Ok("default")
417+
let result1 = await Result.flatMapErrorAsync(
418+
Promise.resolve(Error("timeout")),
419+
asyncRecover,
420+
)
421+
result1 == Ok("default")
422+
423+
let result2 = await Result.flatMapErrorAsync(
424+
Promise.resolve(Ok("default")),
425+
asyncRecover,
426+
)
427+
result2 == Ok("default")
404428
```
405429
*/
406430
let flatMapErrorAsync: (

0 commit comments

Comments
 (0)