Skip to content

Commit fdee9ed

Browse files
authored
Merge branch 'master' into gus/parallel
2 parents be059d7 + c1b8be6 commit fdee9ed

File tree

5 files changed

+108
-12
lines changed

5 files changed

+108
-12
lines changed

.github/workflows/dotnetcore.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ env:
55
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
66
# Disable sending usage data to Microsoft
77
DOTNET_CLI_TELEMETRY_OPTOUT: true
8-
# GitHub Packages Feed settings
9-
GITHUB_FEED: https://nuget.pkg.github.com/fsprojects
10-
GITHUB_USER: fsprojects
11-
#GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128

139
on:
1410
push:
@@ -41,7 +37,9 @@ jobs:
4137

4238
package:
4339
runs-on: windows-latest
44-
40+
permissions:
41+
packages: write
42+
contents: read
4543
steps:
4644
- uses: actions/checkout@v2
4745
- name: Setup .NET Core
@@ -74,13 +72,14 @@ jobs:
7472
with:
7573
name: nupkg
7674
path: ./bin/nupkg/*.nupkg
77-
#- name: Push to GitHub Feed
78-
# shell: bash
79-
# run: |
80-
# for f in ./bin/nupkg/*.nupkg
81-
# do
82-
# curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
83-
# done
75+
- name: Push to GitHub Feed
76+
shell: bash
77+
run: |
78+
for f in ./bin/nupkg/*.nupkg
79+
do
80+
echo $f
81+
dotnet nuget push $f -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
82+
done
8483
8584
docs:
8685
runs-on: windows-latest

src/FSharpPlus/Extensions/Array.fs

+22
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ module Array =
238238

239239
Array.init (min a1.Length a2.Length) (fun i -> f a1.[i] a2.[i])
240240

241+
/// <summary>Safely build a new array whose elements are the results of applying the given function
242+
/// to each of the elements of the three arrays pairwise.</summary>
243+
/// <remark>If one array is shorter, excess elements are discarded from the right end of the longer array.</remark>
244+
let map3Shortest f (a1: 'T1 []) (a2: 'T2 []) (a3: 'T3 []) =
245+
raiseIfNull (nameof a1) a1
246+
raiseIfNull (nameof a2) a2
247+
raiseIfNull (nameof a3) a3
248+
Array.init (min a1.Length a2.Length |> min a3.Length) (fun i -> f a1.[i] a2.[i] a3.[i])
249+
241250
/// <summary>
242251
/// Zip safely two arrays. If one array is shorter, excess elements are discarded from the right end of the longer array.
243252
/// </summary>
@@ -250,6 +259,19 @@ module Array =
250259

251260
Array.init (min a1.Length a2.Length) (fun i -> a1.[i], a2.[i])
252261

262+
/// <summary>
263+
/// Zip safely three arrays. If one array is shorter, excess elements are discarded from the right end of the longer array.
264+
/// </summary>
265+
/// <param name="a1">First input array.</param>
266+
/// <param name="a2">Second input array.</param>
267+
/// <param name="a3">Third input array.</param>
268+
/// <returns>Array with corresponding tuple of input arrays.</returns>
269+
let zip3Shortest (a1: array<'T1>) (a2: array<'T2>) (a3: array<'T3>) =
270+
raiseIfNull (nameof a1) a1
271+
raiseIfNull (nameof a2) a2
272+
raiseIfNull (nameof a3) a3
273+
Array.init (min a1.Length a2.Length |> min a3.Length) (fun i -> a1.[i], a2.[i], a3.[i])
274+
253275
/// <summary>Same as choose but with access to the index.</summary>
254276
/// <param name="mapping">The mapping function, taking index and element as parameters.</param>
255277
/// <param name="source">The input array.</param>

src/FSharpPlus/Extensions/ResizeArray.fs

+24
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ module ResizeArray =
134134
ra.Add (f a1.[i] a2.[i])
135135
ra
136136

137+
/// <summary>Safely build a new ResizeArray whose elements are the results of applying the given function
138+
/// to each of the elements of the three ResizeArrays pairwise.</summary>
139+
/// <remark>If one array is shorter, excess elements are discarded from the right end of the longer array.</remark>
140+
let map3Shortest f (a1: ResizeArray<'T1>) (a2: ResizeArray<'T2>) (a3: ResizeArray<'T3>) =
141+
let len = min a1.Count a2.Count |> min a3.Count
142+
let ra = ResizeArray len
143+
for i in 0..(len-1) do
144+
ra.Add (f a1.[i] a2.[i] a3.[i])
145+
ra
146+
137147
/// <summary>
138148
/// Zip safely two ResizeArrays. If one ResizeArray is shorter, excess elements are discarded from the right end of the longer ResizeArray.
139149
/// </summary>
@@ -146,3 +156,17 @@ module ResizeArray =
146156
for i in 0..(len-1) do
147157
ra.Add (a1.[i], a2.[i])
148158
ra
159+
160+
/// <summary>
161+
/// Zip safely three ResizeArrays. If one ResizeArray is shorter, excess elements are discarded from the right end of the longer ResizeArray.
162+
/// </summary>
163+
/// <param name="a1">First input ResizeArray.</param>
164+
/// <param name="a2">Second input ResizeArray.</param>
165+
/// <param name="a3">Third input ResizeArray.</param>
166+
/// <returns>ResizeArray with corresponding pairs of input ResizeArrays.</returns>
167+
let zip3Shortest (a1: ResizeArray<'T1>) (a2: ResizeArray<'T2>) (a3: ResizeArray<'T3>) =
168+
let len = min a1.Count a2.Count |> min a3.Count
169+
let ra = ResizeArray len
170+
for i in 0..(len-1) do
171+
ra.Add (a1.[i], a2.[i], a3.[i])
172+
ra

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)