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 =
1212 let mapError f tr =
1313 Task.map ( Result.mapError f) tr
1414
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))
2318
2419 let foldResult onSuccess onError tr =
2520 Task.map ( Result.fold onSuccess onError) tr
Original file line number Diff line number Diff line change @@ -11,31 +11,30 @@ module AsyncResult =
1111 let mapError f ar =
1212 Async.map ( Result.mapError f) ar
1313
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))
2217
2318 let foldResult onSuccess onError ar =
2419 Async.map ( Result.fold onSuccess onError) ar
2520
2621#if ! FABLE_ COMPILER
2722
2823 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+ )
3330
3431 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+ )
3938
4039#endif
4140
You can’t perform that action at this time.
0 commit comments