File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
src/FsToolkit.ErrorHandling.TaskResult
tests/FsToolkit.ErrorHandling.TaskResult.Tests Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -237,3 +237,13 @@ module TaskResult =
237237 let inline ofResult ( x : Result < _ , _ >) =
238238 x
239239 |> Task.singleton
240+
241+ /// Bind the TaskResult and requireSome on the inner option value.
242+ let inline bindRequireSome error x =
243+ x
244+ |> bind ( Result.requireSome error >> Task.singleton)
245+
246+ /// Bind the TaskResult and requireNone on the inner option value.
247+ let inline bindRequireNone error x =
248+ x
249+ |> bind ( Result.requireNone error >> Task.singleton)
Original file line number Diff line number Diff line change @@ -823,3 +823,19 @@ let TaskResultOperatorTests =
823823 )
824824 |> Expect.hasTaskOkValueSync ( PostId newPostId)
825825 ]
826+
827+ [<Tests>]
828+ let TaskResultBindRequireTests =
829+ testList " TeskResult Bind + Require Tests" [
830+ testCase " bindRequireNone"
831+ <| fun _ ->
832+ let user = Some " john_doe" |> Ok |> Task.singleton
833+ let error = user |> TaskResult.bindRequireNone " User exists"
834+ error |> Expect.hasTaskErrorValueSync " User exists"
835+
836+ testCase " bindRequireSome"
837+ <| fun _ ->
838+ let user = Some " john_doe" |> Ok |> Task.singleton
839+ let error = user |> TaskResult.bindRequireSome " User doesn't exist"
840+ error |> Expect.hasTaskOkValueSync " john_doe"
841+ ]
You can’t perform that action at this time.
0 commit comments