File tree Expand file tree Collapse file tree 2 files changed +18
-24
lines changed
FsToolkit.ErrorHandling.TaskResult Expand file tree Collapse file tree 2 files changed +18
-24
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,9 @@ module TaskResult =
12
12
let mapError f tr =
13
13
Task.map ( Result.mapError f) tr
14
14
15
- let bind f ( tr : Task < _ >) = task {
16
- let! result = tr
17
- let t =
18
- match result with
19
- | Ok x -> f x
20
- | Error e -> task { return Error e }
21
- return ! t
22
- }
15
+ let bind f ( tr : Task < _ >) =
16
+ tr
17
+ |> Task.bind( Result.either f ( Error >> Task.singleton))
23
18
24
19
let foldResult onSuccess onError tr =
25
20
Task.map ( Result.fold onSuccess onError) tr
Original file line number Diff line number Diff line change @@ -11,31 +11,30 @@ module AsyncResult =
11
11
let mapError f ar =
12
12
Async.map ( Result.mapError f) ar
13
13
14
- let bind f ar = async {
15
- let! result = ar
16
- let t =
17
- match result with
18
- | Ok x -> f x
19
- | Error e -> async { return Error e }
20
- return ! t
21
- }
14
+ let bind f ar =
15
+ ar
16
+ |> Async.bind( Result.either f ( Error >> Async.singleton))
22
17
23
18
let foldResult onSuccess onError ar =
24
19
Async.map ( Result.fold onSuccess onError) ar
25
20
26
21
#if ! FABLE_ COMPILER
27
22
28
23
let ofTask aTask =
29
- aTask
30
- |> Async.AwaitTask
31
- |> Async.Catch
32
- |> Async.map Result.ofChoice
24
+ async.Delay( fun () ->
25
+ aTask
26
+ |> Async.AwaitTask
27
+ |> Async.Catch
28
+ |> Async.map Result.ofChoice
29
+ )
33
30
34
31
let ofTaskAction ( aTask : Task ) =
35
- aTask
36
- |> Async.AwaitTask
37
- |> Async.Catch
38
- |> Async.map Result.ofChoice
32
+ async.Delay( fun () ->
33
+ aTask
34
+ |> Async.AwaitTask
35
+ |> Async.Catch
36
+ |> Async.map Result.ofChoice
37
+ )
39
38
40
39
#endif
41
40
You can’t perform that action at this time.
0 commit comments