Skip to content

Commit c7f94d6

Browse files
isaacabrahamTheAngryByrd
authored andcommitted
Small refactor
1 parent f849103 commit c7f94d6

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/FsToolkit.ErrorHandling/List.fs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ namespace FsToolkit.ErrorHandling
44
module List =
55

66
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 ->
1311
let r = result {
1412
let! y = f x
1513
let! ys = state
@@ -22,10 +20,7 @@ module List =
2220
let rec private traverseAsyncResultM' (state : Async<Result<_,_>>) (f : _ -> Async<Result<_,_>>) xs =
2321
match xs with
2422
| [] ->
25-
asyncResult {
26-
let! v = state
27-
return List.rev v
28-
}
23+
state |> AsyncResult.map List.rev
2924
| x :: xs ->
3025
async {
3126
let! r = asyncResult {
@@ -52,12 +47,10 @@ module List =
5247

5348

5449
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 ->
6154
let fR =
6255
f x |> Result.mapError List.singleton
6356
match state, fR with
@@ -92,12 +85,10 @@ module List =
9285
traverseResultA id xs
9386

9487
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 ->
10192
let fR = f x
10293
match state, fR with
10394
| Ok ys, Ok y ->

0 commit comments

Comments
 (0)