File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/FsToolkit.ErrorHandling
tests/FsToolkit.ErrorHandling.TaskResult.Tests Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 11namespace FsToolkit.ErrorHandling
22
3+ open System
34open System.Threading .Tasks
45open System.Runtime .CompilerServices
56open System.Threading
@@ -554,6 +555,19 @@ module TaskValidationCEExtensionsMediumPriority =
554555 |> Async.map Ok
555556 |> Async.StartImmediateAsTask
556557
558+ member inline _.Source ( s : Async < Result < 'ok , 'error >>) : TaskValidation < 'ok , 'error > =
559+ s
560+ |> AsyncResult.mapError List.singleton
561+ |> Async.StartImmediateAsTask
562+
563+ member inline _.Source ( s : Task < Result < 'ok , 'error >>) : TaskValidation < 'ok , 'error > =
564+ TaskResult.mapError List.singleton s
565+
566+ member inline _.Source ( result : Result < _ , _ >) : Task < Validation < _ , _ >> =
567+ result
568+ |> Validation.ofResult
569+ |> Task.singleton
570+
557571[<AutoOpen>]
558572module TaskValidationCEExtensionsHighPriority2 =
559573
Original file line number Diff line number Diff line change @@ -674,6 +674,31 @@ let ``TaskValidationCE applicative tests`` =
674674 Expect.equal actual ( Validation.ok 6 ) " Should be ok"
675675 }
676676
677+ testCaseTask " Fail Path Result"
678+ <| fun () ->
679+ task {
680+ let expected =
681+ Error [
682+ " Error 1"
683+ " Error 2"
684+ ]
685+
686+ let! actual =
687+ taskValidation {
688+ let! a = Ok 3
689+ and! b = Ok 2
690+ and! c = Error " Error 1"
691+ and! d = Error " Error 2"
692+
693+ return
694+ a + b
695+ - c
696+ - d
697+ }
698+
699+ Expect.equal actual expected " Should be Error"
700+ }
701+
677702 testCaseTask " Fail Path Validation"
678703 <| fun () ->
679704 task {
You can’t perform that action at this time.
0 commit comments