Skip to content

Commit c1b8be6

Browse files
committed
+ pmap2 and pmap3 to Task and ValueTask
1 parent 3e7a328 commit c1b8be6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/FSharpPlus/Extensions/Task.fs

+22
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@ module Task =
134134
) |> ignore) |> ignore) |> ignore
135135
tcs.Task
136136

137+
/// <summary>Creates a task workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
138+
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
139+
/// <param name="f">The mapping function.</param>
140+
/// <param name="x">First task workflow.</param>
141+
/// <param name="y">Second task workflow.</param>
142+
let pmap2 f x y = task {
143+
let! x' = x
144+
let! y' = y
145+
return f x' y' }
146+
147+
/// <summary>Creates a task workflow from three workflows 'x', 'y' and z, mapping its results with 'f'.</summary>
148+
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
149+
/// <param name="f">The mapping function.</param>
150+
/// <param name="x">First task workflow.</param>
151+
/// <param name="y">Second task workflow.</param>
152+
/// <param name="z">Third task workflow.</param>
153+
let pmap3 f x y z = task {
154+
let! x' = x
155+
let! y' = y
156+
let! z' = z
157+
return f x' y' z' }
158+
137159
/// <summary>Creates a task workflow that is the result of applying the resulting function of a task workflow
138160
/// to the resulting value of another task workflow</summary>
139161
/// <param name="f">Task workflow returning a function</param>

src/FSharpPlus/Extensions/ValueTask.fs

+29
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,35 @@ module ValueTask =
6262
with e -> tcs.SetException e)))
6363
tcs.Task |> ValueTask<'W>
6464

65+
/// <summary>Creates a task workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
66+
/// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
67+
/// <param name="f">The mapping function.</param>
68+
/// <param name="x">First ValueTask workflow.</param>
69+
/// <param name="y">Second ValueTask workflow.</param>
70+
/// <param name="z">Third ValueTask workflow.</param>
71+
let pmap2 (f: 'T -> 'U -> 'V) (x: ValueTask<'T>) (y: ValueTask<'U>) : ValueTask<'V> =
72+
task {
73+
let! x' = x
74+
let! y' = y
75+
return f x' y'
76+
}
77+
|> ValueTask<'V>
78+
79+
/// <summary>Creates a ValueTask workflow from three workflows 'x', 'y' and z, mapping its results with 'f'.</summary>
80+
/// <remarks>Similar to map3 but workflows are run in parallel.</remarks>
81+
/// <param name="f">The mapping function.</param>
82+
/// <param name="x">First ValueTask workflow.</param>
83+
/// <param name="y">Second ValueTask workflow.</param>
84+
/// <param name="z">Third ValueTask workflow.</param>
85+
let pmap3 (f: 'T -> 'U -> 'V -> 'W) (x: ValueTask<'T>) (y: ValueTask<'U>) (z: ValueTask<'V>) : ValueTask<'W> =
86+
task {
87+
let! x' = x
88+
let! y' = y
89+
let! z' = z
90+
return f x' y' z'
91+
}
92+
|> ValueTask<'W>
93+
6594
/// <summary>Creates a ValueTask workflow that is the result of applying the resulting function of a ValueTask workflow
6695
/// to the resulting value of another ValueTask workflow</summary>
6796
/// <param name="f">ValueTask workflow returning a function</param>

0 commit comments

Comments
 (0)