Skip to content

Commit

Permalink
Merge branch 'master' into gus/parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty authored Jan 13, 2024
2 parents be059d7 + c1b8be6 commit fdee9ed
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 12 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# GitHub Packages Feed settings
GITHUB_FEED: https://nuget.pkg.github.com/fsprojects
GITHUB_USER: fsprojects
#GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
push:
Expand Down Expand Up @@ -41,7 +37,9 @@ jobs:

package:
runs-on: windows-latest

permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
Expand Down Expand Up @@ -74,13 +72,14 @@ jobs:
with:
name: nupkg
path: ./bin/nupkg/*.nupkg
#- name: Push to GitHub Feed
# shell: bash
# run: |
# for f in ./bin/nupkg/*.nupkg
# do
# curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
# done
- name: Push to GitHub Feed
shell: bash
run: |
for f in ./bin/nupkg/*.nupkg
do
echo $f
dotnet nuget push $f -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
done
docs:
runs-on: windows-latest
Expand Down
22 changes: 22 additions & 0 deletions src/FSharpPlus/Extensions/Array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ module Array =

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

/// <summary>Safely build a new array whose elements are the results of applying the given function
/// to each of the elements of the three arrays pairwise.</summary>
/// <remark>If one array is shorter, excess elements are discarded from the right end of the longer array.</remark>
let map3Shortest f (a1: 'T1 []) (a2: 'T2 []) (a3: 'T3 []) =
raiseIfNull (nameof a1) a1
raiseIfNull (nameof a2) a2
raiseIfNull (nameof a3) a3
Array.init (min a1.Length a2.Length |> min a3.Length) (fun i -> f a1.[i] a2.[i] a3.[i])

/// <summary>
/// Zip safely two arrays. If one array is shorter, excess elements are discarded from the right end of the longer array.
/// </summary>
Expand All @@ -250,6 +259,19 @@ module Array =

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

/// <summary>
/// Zip safely three arrays. If one array is shorter, excess elements are discarded from the right end of the longer array.
/// </summary>
/// <param name="a1">First input array.</param>
/// <param name="a2">Second input array.</param>
/// <param name="a3">Third input array.</param>
/// <returns>Array with corresponding tuple of input arrays.</returns>
let zip3Shortest (a1: array<'T1>) (a2: array<'T2>) (a3: array<'T3>) =
raiseIfNull (nameof a1) a1
raiseIfNull (nameof a2) a2
raiseIfNull (nameof a3) a3
Array.init (min a1.Length a2.Length |> min a3.Length) (fun i -> a1.[i], a2.[i], a3.[i])

/// <summary>Same as choose but with access to the index.</summary>
/// <param name="mapping">The mapping function, taking index and element as parameters.</param>
/// <param name="source">The input array.</param>
Expand Down
24 changes: 24 additions & 0 deletions src/FSharpPlus/Extensions/ResizeArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ module ResizeArray =
ra.Add (f a1.[i] a2.[i])
ra

/// <summary>Safely build a new ResizeArray whose elements are the results of applying the given function
/// to each of the elements of the three ResizeArrays pairwise.</summary>
/// <remark>If one array is shorter, excess elements are discarded from the right end of the longer array.</remark>
let map3Shortest f (a1: ResizeArray<'T1>) (a2: ResizeArray<'T2>) (a3: ResizeArray<'T3>) =
let len = min a1.Count a2.Count |> min a3.Count
let ra = ResizeArray len
for i in 0..(len-1) do
ra.Add (f a1.[i] a2.[i] a3.[i])
ra

/// <summary>
/// Zip safely two ResizeArrays. If one ResizeArray is shorter, excess elements are discarded from the right end of the longer ResizeArray.
/// </summary>
Expand All @@ -146,3 +156,17 @@ module ResizeArray =
for i in 0..(len-1) do
ra.Add (a1.[i], a2.[i])
ra

/// <summary>
/// Zip safely three ResizeArrays. If one ResizeArray is shorter, excess elements are discarded from the right end of the longer ResizeArray.
/// </summary>
/// <param name="a1">First input ResizeArray.</param>
/// <param name="a2">Second input ResizeArray.</param>
/// <param name="a3">Third input ResizeArray.</param>
/// <returns>ResizeArray with corresponding pairs of input ResizeArrays.</returns>
let zip3Shortest (a1: ResizeArray<'T1>) (a2: ResizeArray<'T2>) (a3: ResizeArray<'T3>) =
let len = min a1.Count a2.Count |> min a3.Count
let ra = ResizeArray len
for i in 0..(len-1) do
ra.Add (a1.[i], a2.[i], a3.[i])
ra
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 fdee9ed

Please sign in to comment.