File tree Expand file tree Collapse file tree 2 files changed +38
-7
lines changed
src/FsToolkit.ErrorHandling
tests/FsToolkit.ErrorHandling.Tests Expand file tree Collapse file tree 2 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -339,17 +339,17 @@ module Option =
339339 }
340340
341341 /// <summary>
342- /// Maps a <c>Task</c> function over an <c>option</c>, returning a <c>Task<'T option></c><br/>
342+ /// Maps a <c>Task</c> function over an <c>option</c>, returning a <c>Task<'U option></c><br/>
343343 ///
344344 /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traversetask</href>
345345 /// </summary>
346346 /// <param name="f">The function to map over the <c>option</c>.</param>
347347 /// <param name="opt">The <c>option</c> to map over.</param>
348- /// <returns>A <c>Task<'T option></c> with the mapped value.</returns>
348+ /// <returns>A <c>Task<'U option></c> with the mapped value.</returns>
349349 let inline traverseTask
350- ( [<InlineIfLambda>] f : 'T -> Task < 'T >)
350+ ( [<InlineIfLambda>] f : 'T -> Task < 'U >)
351351 ( opt : Option < 'T >)
352- : Task < Option < 'T >> =
352+ : Task < Option < 'U >> =
353353 sequenceTask (( map f) opt)
354354
355355 /// <summary>
@@ -407,11 +407,11 @@ module Option =
407407 /// </summary>
408408 /// <param name="f">The function to map over the Option.</param>
409409 /// <param name="opt">The Option to map over.</param>
410- /// <returns>An Async Option with the mapped value.</returns>
410+ /// <returns>An <c> Async< Option<'U>></c> with the mapped value.</returns>
411411 let inline traverseAsync
412- ( [<InlineIfLambda>] f : 'T -> Async < 'T >)
412+ ( [<InlineIfLambda>] f : 'T -> Async < 'U >)
413413 ( opt : Option < 'T >)
414- : Async < Option < 'T >> =
414+ : Async < Option < 'U >> =
415415 sequenceAsync (( map f) opt)
416416
417417 /// <summary>
Original file line number Diff line number Diff line change @@ -275,6 +275,22 @@ let traverseTaskTests =
275275 Expect.equal value ( Some " foo" ) " "
276276 }
277277
278+ testCaseTask " traverseTask allows mapping to new type"
279+ <| fun () ->
280+ task {
281+ let optTask = Some 100
282+
283+ let optFunc =
284+ string
285+ >> Task.singleton
286+
287+ let! value =
288+ ( optFunc, optTask)
289+ ||> Option.traverseTask
290+
291+ Expect.equal value ( Some " 100" ) " "
292+ }
293+
278294 testCaseTask " traverseTask returns None if None"
279295 <| fun () ->
280296 task {
@@ -439,6 +455,21 @@ let traverseAsyncTests =
439455 Expect.equal value ( Some " foo" ) " "
440456 }
441457
458+ testCaseAsync " traverseAsync allows mapping to different types"
459+ <| async {
460+ let optAsync = Some 100
461+
462+ let optFunc =
463+ ( fun i -> string i)
464+ >> Async.singleton
465+
466+ let! value =
467+ ( optFunc, optAsync)
468+ ||> Option.traverseAsync
469+
470+ Expect.equal value ( Some " 100" ) " "
471+ }
472+
442473 testCaseAsync " traverseAsync returns None if None"
443474 <| async {
444475 let optAsync = None
You can’t perform that action at this time.
0 commit comments