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 =
339
339
}
340
340
341
341
/// <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/>
343
343
///
344
344
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traversetask</href>
345
345
/// </summary>
346
346
/// <param name="f">The function to map over the <c>option</c>.</param>
347
347
/// <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>
349
349
let inline traverseTask
350
- ( [<InlineIfLambda>] f : 'T -> Task < 'T >)
350
+ ( [<InlineIfLambda>] f : 'T -> Task < 'U >)
351
351
( opt : Option < 'T >)
352
- : Task < Option < 'T >> =
352
+ : Task < Option < 'U >> =
353
353
sequenceTask (( map f) opt)
354
354
355
355
/// <summary>
@@ -407,11 +407,11 @@ module Option =
407
407
/// </summary>
408
408
/// <param name="f">The function to map over the Option.</param>
409
409
/// <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>
411
411
let inline traverseAsync
412
- ( [<InlineIfLambda>] f : 'T -> Async < 'T >)
412
+ ( [<InlineIfLambda>] f : 'T -> Async < 'U >)
413
413
( opt : Option < 'T >)
414
- : Async < Option < 'T >> =
414
+ : Async < Option < 'U >> =
415
415
sequenceAsync (( map f) opt)
416
416
417
417
/// <summary>
Original file line number Diff line number Diff line change @@ -275,6 +275,22 @@ let traverseTaskTests =
275
275
Expect.equal value ( Some " foo" ) " "
276
276
}
277
277
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
+
278
294
testCaseTask " traverseTask returns None if None"
279
295
<| fun () ->
280
296
task {
@@ -439,6 +455,21 @@ let traverseAsyncTests =
439
455
Expect.equal value ( Some " foo" ) " "
440
456
}
441
457
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
+
442
473
testCaseAsync " traverseAsync returns None if None"
443
474
<| async {
444
475
let optAsync = None
You can’t perform that action at this time.
0 commit comments