Skip to content

Commit

Permalink
Cannot get Async MergeSources to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed Apr 21, 2020
1 parent e1684c8 commit d9e960e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/FsToolkit.ErrorHandling/AsyncResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ module AsyncResultCE =
this.Delay(fun () -> binder enum.Current)))

member __.BindReturn(x: Async<Result<'T,'U>>, f) = AsyncResult.map f x
member __.BindReturn(x: Result<'T,'U>, f) = __.BindReturn(x |> Async.singleton, f)
member __.BindReturn(x: Choice<'T,'U>, f) = __.BindReturn(x |> Result.ofChoice |> Async.singleton, f)
member __.BindReturn(x: Async<Choice<'T,'U>>, f) = __.BindReturn(x |> Async.map Result.ofChoice, f)

#if !FABLE_COMPILER
member __.BindReturn(x: Task<Result<'T,'U>>, f) = __.BindReturn(x |> Async.AwaitTask, f)
Expand Down Expand Up @@ -168,17 +171,18 @@ module AsyncResultCEExtensions =
#endif


member __.BindReturn(x: Result<'T,'U>, f) = __.BindReturn(x |> Async.singleton, f)
member __.BindReturn(x: Choice<'T,'U>, f) = __.BindReturn(x |> Result.ofChoice |> Async.singleton, f)
member __.BindReturn(x: Async<'T>, f) = __.BindReturn(x |> Async.map Result.Ok, f)
member __.BindReturn(x: Async<Choice<'T,'U>>, f) = __.BindReturn(x |> Async.map Result.ofChoice, f)


#if !FABLE_COMPILER
member __.BindReturn(x: Task<'T>, f) = __.BindReturn(x |> Async.AwaitTask |> Async.map Result.Ok, f)
member __.BindReturn(x: Task, f) = __.BindReturn(x |> Async.AwaitTask |> Async.map Result.Ok, f)
#endif

member __.MergeSources(t1: Async<Result<'T,'U>>, t2: Async<'T1>) = AsyncResult.zip t1 (t2 |> Async.map Result.Ok)
member __.MergeSources(t1: Async<'T>, t2: Async<Result<'T1,'U>>) = AsyncResult.zip (t1 |> Async.map Result.Ok) t2
member __.MergeSources(t1: Async<'T>, t2: Async<'T1>) = AsyncResult.zip (t1 |> Async.map Result.Ok) (t2 |> Async.map Result.Ok)

member __.MergeSources(t1: Async<Result<'T,'U>>, t2: Result<'T1,'U>) = AsyncResult.zip t1 (t2 |> Async.singleton)
member __.MergeSources(t1: Result<'T,'U>, t2: Async<Result<'T1,'U>>) = AsyncResult.zip (t1 |> Async.singleton) t2
member __.MergeSources(t1: Result<'T,'U>, t2: Result<'T1,'U>) = AsyncResult.zip (t1 |> Async.singleton) (t2 |> Async.singleton)
Expand All @@ -190,5 +194,7 @@ module AsyncResultCEExtensions =

member __.MergeSources(t1: Choice<'T,'U>, t2: Result<'T1,'U>) = AsyncResult.zip (t1 |> Result.ofChoice |> Async.singleton) (t2 |> Async.singleton)
member __.MergeSources(t1: Result<'T,'U>, t2: Choice<'T1,'U>) = AsyncResult.zip (t1 |> Async.singleton) (t2 |> Result.ofChoice |> Async.singleton)



let asyncResult = AsyncResultBuilder()
10 changes: 10 additions & 0 deletions tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ let ``AsyncResultCE applicative tests`` =
Expect.equal actual (Ok 4) "Should be ok"
}

testCaseAsync "Happy Path Async" <| async {
let! actual = asyncResult {
let! a = Async.singleton 3
and! b = Async.singleton 2
and! c = Async.singleton 1
return a + b - c
}
Expect.equal actual (Ok 4) "Should be ok"
}

testCaseAsync "Happy Path Result/Choice/AsyncResult" <| async {
let! actual = asyncResult {
let! a = Ok 3
Expand Down

0 comments on commit d9e960e

Please sign in to comment.