File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/FsToolkit.ErrorHandling
tests/FsToolkit.ErrorHandling.Tests Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -333,3 +333,19 @@ module AsyncResult =
333333 let inline ofResult ( x : Result < 'ok , 'error >) : Async < Result < 'ok , 'error >> =
334334 x
335335 |> Async.singleton
336+
337+ /// Bind the AsyncResult and requireSome on the inner option value.
338+ let inline bindRequireSome error x =
339+ x
340+ |> bind (
341+ Result.requireSome error
342+ >> Async.singleton
343+ )
344+
345+ /// Bind the AsyncResult and requireNone on the inner option value.
346+ let inline bindRequireNone error x =
347+ x
348+ |> bind (
349+ Result.requireNone error
350+ >> Async.singleton
351+ )
Original file line number Diff line number Diff line change @@ -795,6 +795,27 @@ let zipErrorTests =
795795 ]
796796
797797
798+ let asyncResultBindRequireTests =
799+ testList " AsyncResult Bind + Require Tests" [
800+ testCaseAsync " bindRequireNone"
801+ <| async {
802+ do !
803+ Some " john_doe"
804+ |> AsyncResult.ok
805+ |> AsyncResult.bindRequireNone " User exists"
806+ |> Expect.hasAsyncErrorValue " User exists"
807+ }
808+
809+ testCaseAsync " bindRequireSome"
810+ <| async {
811+ do !
812+ Some " john_doe"
813+ |> AsyncResult.ok
814+ |> AsyncResult.bindRequireSome " User doesn't exist"
815+ |> Expect.hasAsyncOkValue " john_doe"
816+ }
817+ ]
818+
798819let allTests =
799820 testList " Async Result tests" [
800821 mapTests
@@ -828,4 +849,5 @@ let allTests =
828849 asyncResultOperatorTests
829850 zipTests
830851 zipErrorTests
852+ asyncResultBindRequireTests
831853 ]
You can’t perform that action at this time.
0 commit comments