Skip to content

Commit 279f426

Browse files
isaacabrahamTheAngryByrd
authored andcommitted
traverseResultM'
1 parent d89fca1 commit 279f426

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/FsToolkit.ErrorHandling/List.fs

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

66
let rec private traverseResultM' (state : Result<_,_>) (f : _ -> Result<_,_>) xs =
7-
match xs with
8-
| [] -> state
9-
| x :: xs ->
7+
match state, xs with
8+
| Ok v, [] ->
9+
Ok (List.rev v)
10+
| v, [] ->
11+
v
12+
| _, x :: xs ->
1013
let r = result {
1114
let! y = f x
1215
let! ys = state
13-
return ys @ [y]
16+
return y :: ys
1417
}
1518
match r with
1619
| Ok _ -> traverseResultM' r f xs

0 commit comments

Comments
 (0)