diff --git a/src/FsToolkit.ErrorHandling/Option.fs b/src/FsToolkit.ErrorHandling/Option.fs index 608e7d3e..93ac40c3 100644 --- a/src/FsToolkit.ErrorHandling/Option.fs +++ b/src/FsToolkit.ErrorHandling/Option.fs @@ -339,17 +339,17 @@ module Option = } /// - /// Maps a Task function over an option, returning a Task<'T option>
+ /// Maps a Task function over an option, returning a Task<'U option>
/// /// Documentation is found here: https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traversetask ///
/// The function to map over the option. /// The option to map over. - /// A Task<'T option> with the mapped value. + /// A Task<'U option> with the mapped value. let inline traverseTask - ([] f: 'T -> Task<'T>) + ([] f: 'T -> Task<'U>) (opt: Option<'T>) - : Task> = + : Task> = sequenceTask ((map f) opt) /// @@ -407,11 +407,11 @@ module Option = /// /// The function to map over the Option. /// The Option to map over. - /// An Async Option with the mapped value. + /// An Async<Option<'U>> with the mapped value. let inline traverseAsync - ([] f: 'T -> Async<'T>) + ([] f: 'T -> Async<'U>) (opt: Option<'T>) - : Async> = + : Async> = sequenceAsync ((map f) opt) /// diff --git a/tests/FsToolkit.ErrorHandling.Tests/Option.fs b/tests/FsToolkit.ErrorHandling.Tests/Option.fs index c7a843d1..f5740034 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/Option.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/Option.fs @@ -275,6 +275,22 @@ let traverseTaskTests = Expect.equal value (Some "foo") "" } + testCaseTask "traverseTask allows mapping to new type" + <| fun () -> + task { + let optTask = Some 100 + + let optFunc = + string + >> Task.singleton + + let! value = + (optFunc, optTask) + ||> Option.traverseTask + + Expect.equal value (Some "100") "" + } + testCaseTask "traverseTask returns None if None" <| fun () -> task { @@ -439,6 +455,21 @@ let traverseAsyncTests = Expect.equal value (Some "foo") "" } + testCaseAsync "traverseAsync allows mapping to different types" + <| async { + let optAsync = Some 100 + + let optFunc = + (fun i -> string i) + >> Async.singleton + + let! value = + (optFunc, optAsync) + ||> Option.traverseAsync + + Expect.equal value (Some "100") "" + } + testCaseAsync "traverseAsync returns None if None" <| async { let optAsync = None