Skip to content

Commit

Permalink
+ pmap2 and pmap3 to Task and ValueTask
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Jan 13, 2024
1 parent 3e7a328 commit c1b8be6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/FSharpPlus/Extensions/Task.fs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ module Task =
) |> ignore) |> ignore) |> ignore
tcs.Task

/// <summary>Creates a task workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
/// <param name="f">The mapping function.</param>
/// <param name="x">First task workflow.</param>
/// <param name="y">Second task workflow.</param>
let pmap2 f x y = task {
let! x' = x
let! y' = y
return f x' y' }

/// <summary>Creates a task workflow from three workflows 'x', 'y' and z, mapping its results with 'f'.</summary>
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
/// <param name="f">The mapping function.</param>
/// <param name="x">First task workflow.</param>
/// <param name="y">Second task workflow.</param>
/// <param name="z">Third task workflow.</param>
let pmap3 f x y z = task {
let! x' = x
let! y' = y
let! z' = z
return f x' y' z' }

/// <summary>Creates a task workflow that is the result of applying the resulting function of a task workflow
/// to the resulting value of another task workflow</summary>
/// <param name="f">Task workflow returning a function</param>
Expand Down
29 changes: 29 additions & 0 deletions src/FSharpPlus/Extensions/ValueTask.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ module ValueTask =
with e -> tcs.SetException e)))
tcs.Task |> ValueTask<'W>

/// <summary>Creates a task workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
/// <param name="f">The mapping function.</param>
/// <param name="x">First ValueTask workflow.</param>
/// <param name="y">Second ValueTask workflow.</param>
/// <param name="z">Third ValueTask workflow.</param>
let pmap2 (f: 'T -> 'U -> 'V) (x: ValueTask<'T>) (y: ValueTask<'U>) : ValueTask<'V> =
task {
let! x' = x
let! y' = y
return f x' y'
}
|> ValueTask<'V>

/// <summary>Creates a ValueTask workflow from three workflows 'x', 'y' and z, mapping its results with 'f'.</summary>
/// <remarks>Similar to map3 but workflows are run in parallel.</remarks>
/// <param name="f">The mapping function.</param>
/// <param name="x">First ValueTask workflow.</param>
/// <param name="y">Second ValueTask workflow.</param>
/// <param name="z">Third ValueTask workflow.</param>
let pmap3 (f: 'T -> 'U -> 'V -> 'W) (x: ValueTask<'T>) (y: ValueTask<'U>) (z: ValueTask<'V>) : ValueTask<'W> =
task {
let! x' = x
let! y' = y
let! z' = z
return f x' y' z'
}
|> ValueTask<'W>

/// <summary>Creates a ValueTask workflow that is the result of applying the resulting function of a ValueTask workflow
/// to the resulting value of another ValueTask workflow</summary>
/// <param name="f">ValueTask workflow returning a function</param>
Expand Down

0 comments on commit c1b8be6

Please sign in to comment.