Skip to content

Commit 1115022

Browse files
committed
Refactor
1 parent 14f57a7 commit 1115022

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Insurello.AsyncExtra/AsyncExtra.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ module AsyncResult =
7777

7878
let traverse : ('a -> 'b) -> List<AsyncResult<'a, 'err>> -> AsyncResult<'b list, 'err> =
7979
fun transformer list ->
80-
let rec fold acc =
81-
function
80+
let cons tail head = head :: tail
81+
82+
let rec fold remaining acc =
83+
match remaining with
8284
| [] -> acc |> List.rev |> singleton
83-
| xA :: xAs -> bind (fun x -> fold (transformer x :: acc) xAs) xA
85+
| xA :: xAs -> xA |> bind (transformer >> cons acc >> fold xAs)
8486

85-
fold [] list
87+
fold list []
8688

8789
let sequence : List<AsyncResult<'a, 'error>> -> AsyncResult<'a list, 'error> = fun list -> traverse id list
8890

0 commit comments

Comments
 (0)