File tree Expand file tree Collapse file tree 1 file changed +13
-22
lines changed
src/FsToolkit.ErrorHandling Expand file tree Collapse file tree 1 file changed +13
-22
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,10 @@ namespace FsToolkit.ErrorHandling
4
4
module List =
5
5
6
6
let rec private traverseResultM ' ( state : Result < _ , _ >) ( f : _ -> Result < _ , _ >) xs =
7
- match state, xs with
8
- | Ok v, [] ->
9
- Ok ( List.rev v)
10
- | v, [] ->
11
- v
12
- | _, x :: xs ->
7
+ match xs with
8
+ | [] ->
9
+ state |> Result.map List.rev
10
+ | x :: xs ->
13
11
let r = result {
14
12
let! y = f x
15
13
let! ys = state
@@ -22,10 +20,7 @@ module List =
22
20
let rec private traverseAsyncResultM ' ( state : Async < Result < _ , _ >>) ( f : _ -> Async < Result < _ , _ >>) xs =
23
21
match xs with
24
22
| [] ->
25
- asyncResult {
26
- let! v = state
27
- return List.rev v
28
- }
23
+ state |> AsyncResult.map List.rev
29
24
| x :: xs ->
30
25
async {
31
26
let! r = asyncResult {
@@ -52,12 +47,10 @@ module List =
52
47
53
48
54
49
let rec private traverseResultA ' state f xs =
55
- match state, xs with
56
- | Ok v, [] ->
57
- Ok ( List.rev v)
58
- | v, [] ->
59
- v
60
- | _, x :: xs ->
50
+ match xs with
51
+ | [] ->
52
+ state |> Result.map List.rev
53
+ | x :: xs ->
61
54
let fR =
62
55
f x |> Result.mapError List.singleton
63
56
match state, fR with
@@ -92,12 +85,10 @@ module List =
92
85
traverseResultA id xs
93
86
94
87
let rec traverseValidationA ' state f xs =
95
- match state, xs with
96
- | Ok items, [] ->
97
- Ok ( List.rev items)
98
- | errors, [] ->
99
- errors
100
- | _, x :: xs ->
88
+ match xs with
89
+ | [] ->
90
+ state |> Result.map List.rev
91
+ | x :: xs ->
101
92
let fR = f x
102
93
match state, fR with
103
94
| Ok ys, Ok y ->
You can’t perform that action at this time.
0 commit comments