File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/FsToolkit.ErrorHandling.JobResult
tests/FsToolkit.ErrorHandling.JobResult.Tests Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -249,3 +249,19 @@ module JobResult =
249249 let inline ofResult ( x : Result < _ , _ >) =
250250 x
251251 |> Job.singleton
252+
253+ /// Bind the JobResult and requireSome on the inner option value.
254+ let inline bindRequireSome error x =
255+ x
256+ |> bind (
257+ Result.requireSome error
258+ >> Job.singleton
259+ )
260+
261+ /// Bind the JobResult and requireNone on the inner option value.
262+ let inline bindRequireNone error x =
263+ x
264+ |> bind (
265+ Result.requireNone error
266+ >> Job.singleton
267+ )
Original file line number Diff line number Diff line change @@ -753,6 +753,27 @@ let zipErrorTests =
753753 Expect.hasJobValue ( Error( " Bad1" , " Bad2" )) v
754754 ]
755755
756+ [<Tests>]
757+ let bindRequireTests =
758+ testList " JobResult Bind + Require tests" [
759+ testCaseJob " bindRequireNone"
760+ <| job {
761+ return !
762+ Some " john_doe"
763+ |> JobResult.ok
764+ |> JobResult.bindRequireNone " user exists"
765+ |> Expect.hasJobErrorValue " user exists"
766+ }
767+
768+ testCaseJob " bindRequireSome"
769+ <| job {
770+ return !
771+ Some " john_doe"
772+ |> JobResult.ok
773+ |> JobResult.bindRequireSome " user doesn't exists"
774+ |> Expect.hasJobOkValue " john_doe"
775+ }
776+ ]
756777
757778type CreatePostResult =
758779 | PostSuccess of NotifyNewPostRequest
You can’t perform that action at this time.
0 commit comments