Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Async<'value voption> support to asyncOptionCE #226

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/FsToolkit.ErrorHandling/AsyncOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ module AsyncOptionCE =
else
this.Bind(computation, (fun () -> this.While(guard, computation)))


/// <summary>
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(vopt: Async<'value voption>) : Async<'value option> =
async {
let! v = vopt
return Option.ofValueOption v
}


/// <summary>
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
///
Expand Down
24 changes: 24 additions & 0 deletions tests/FsToolkit.ErrorHandling.Tests/AsyncOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ let ``AsyncOptionCE return! Tests`` =
Expect.equal actual (data) "Should be ok"
}

testCaseAsync "Return ValueSome AsyncOption"
<| async {
let innerData = "Foo"
let data = ValueSome innerData
let! actual = asyncOption { return! data }

Expect.equal actual (data) "Should be ok"
}

testCaseAsync "Return Some AsyncOption"
<| async {
let innerData = "Foo"
Expand Down Expand Up @@ -96,6 +105,21 @@ let ``AsyncOptionCE bind Tests`` =

}

testCaseAsync "Bind ValueSome AsyncOption"
<| async {
let innerData = "Foo"
let data = ValueSome innerData

let! actual =
asyncOption {
let! data = data
return data
}

Expect.equal actual (data) "Should be ok"

}

testCaseAsync "Bind Some AsyncOption"
<| async {
let innerData = "Foo"
Expand Down
Loading