Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacabraham authored and TheAngryByrd committed Feb 26, 2021
1 parent f849103 commit c7f94d6
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/FsToolkit.ErrorHandling/List.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ namespace FsToolkit.ErrorHandling
module List =

let rec private traverseResultM' (state : Result<_,_>) (f : _ -> Result<_,_>) xs =
match state, xs with
| Ok v, [] ->
Ok (List.rev v)
| v, [] ->
v
| _, x :: xs ->
match xs with
| [] ->
state |> Result.map List.rev
| x :: xs ->
let r = result {
let! y = f x
let! ys = state
Expand All @@ -22,10 +20,7 @@ module List =
let rec private traverseAsyncResultM' (state : Async<Result<_,_>>) (f : _ -> Async<Result<_,_>>) xs =
match xs with
| [] ->
asyncResult {
let! v = state
return List.rev v
}
state |> AsyncResult.map List.rev
| x :: xs ->
async {
let! r = asyncResult {
Expand All @@ -52,12 +47,10 @@ module List =


let rec private traverseResultA' state f xs =
match state, xs with
| Ok v, [] ->
Ok (List.rev v)
| v, [] ->
v
| _, x :: xs ->
match xs with
| [] ->
state |> Result.map List.rev
| x :: xs ->
let fR =
f x |> Result.mapError List.singleton
match state, fR with
Expand Down Expand Up @@ -92,12 +85,10 @@ module List =
traverseResultA id xs

let rec traverseValidationA' state f xs =
match state, xs with
| Ok items, [] ->
Ok (List.rev items)
| errors, [] ->
errors
| _, x :: xs ->
match xs with
| [] ->
state |> Result.map List.rev
| x :: xs ->
let fR = f x
match state, fR with
| Ok ys, Ok y ->
Expand Down

0 comments on commit c7f94d6

Please sign in to comment.