Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"isRoot": true,
"tools": {
"fable": {
"version": "4.0.6",
"version": "4.24.0",
"commands": [
"fable"
]
],
"rollForward": false
}
}
}
16 changes: 8 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.x.x
dotnet-version: 8.x.x
- name: Restore fable
run: dotnet tool restore
- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
- name: install node modules
Expand All @@ -36,15 +36,15 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.x.x
dotnet-version: 8.x.x
- name: Restore fable
run: dotnet tool restore
- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
- name: install node modules
Expand Down
2 changes: 2 additions & 0 deletions FSharpAux.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{7C6D08
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
build.sh = build.sh
.config\dotnet-tools.json = .config\dotnet-tools.json
global.json = global.json
package.json = package.json
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

### Requirements

- .Net 6.0
- .Net 8.0
- node.js ~16 (higher might work) [only for fable testing]
- npm ~8 (higher might work) [only for fable testing]

Expand Down
1 change: 0 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@echo off
cls

dotnet run --project ./build/build.fsproj %*
16 changes: 15 additions & 1 deletion build/BasicTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@ let clean = BuildTask.create "Clean" [] {

let build = BuildTask.create "Build" [clean] {
solutionFile
|> DotNet.build id
|> DotNet.build (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"warnon", "3390"
])
DisableInternalBinLog = true
}
{
p with
MSBuildParams = msBuildParams

}
|> DotNet.Options.withCustomParams (Some "-tl")
)
}
5 changes: 5 additions & 0 deletions build/PackageTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open TestTasks

open BlackFox.Fake
open Fake.Core
open Fake.DotNet
open Fake.IO.Globbing.Operators

let pack = BuildTask.create "Pack" [clean; build; runTests] {
Expand All @@ -22,12 +23,14 @@ let pack = BuildTask.create "Pack" [clean; build; runTests] {
"Version",stableVersionTag
"PackageReleaseNotes", (release.Notes |> String.concat "\r\n")
] @ p.MSBuildParams.Properties)
DisableInternalBinLog = true
}
{
p with
MSBuildParams = msBuildParams
OutputPath = Some pkgDir
}
|> DotNet.Options.withCustomParams (Some "--no-dependencies -tl")
))
else failwith "aborted"
}
Expand All @@ -44,13 +47,15 @@ let packPrerelease = BuildTask.create "PackPrerelease" [setPrereleaseTag; clean;
"Version", prereleaseTag
"PackageReleaseNotes", (release.Notes |> String.toLines )
] @ p.MSBuildParams.Properties)
DisableInternalBinLog = true
}
{
p with
VersionSuffix = Some prereleaseSuffix
OutputPath = Some pkgDir
MSBuildParams = msBuildParams
}
|> DotNet.Options.withCustomParams (Some "--no-dependencies -tl")
))
else
failwith "aborted"
Expand Down
1 change: 1 addition & 0 deletions build/TestTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ module RunTests =
Logger = Some "console;verbosity=detailed"
Configuration = DotNet.BuildConfiguration.fromString configuration
NoBuild = true
MSBuildParams = { testParams.MSBuildParams with DisableInternalBinLog = true }
}
) testProject
)
Expand Down
20 changes: 10 additions & 10 deletions build/build.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -18,15 +18,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BlackFox.Fake.BuildTask" Version="0.1.3" />
<PackageReference Include="Fake.Api.Github" Version="5.22.0" />
<PackageReference Include="Fake.Core.Process" Version="5.22.0" />
<PackageReference Include="Fake.Core.ReleaseNotes" Version="5.22.0" />
<PackageReference Include="Fake.Core.Target" Version="5.22.0" />
<PackageReference Include="Fake.DotNet.Cli" Version="5.22.0" />
<PackageReference Include="Fake.DotNet.MSBuild" Version="5.22.0" />
<PackageReference Include="Fake.IO.FileSystem" Version="5.22.0" />
<PackageReference Include="Fake.Tools.Git" Version="5.22.0" />
<PackageReference Include="BlackFox.Fake.BuildTask" Version="0.1.3" />
<PackageReference Include="Fake.Api.Github" Version="6.0.0" />
<PackageReference Include="Fake.Core.Process" Version="6.0.0" />
<PackageReference Include="Fake.Core.ReleaseNotes" Version="6.0.0" />
<PackageReference Include="Fake.Core.Target" Version="6.0.0" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick question: Wasn't it the case that we wanted to keep all version tags exact? (I.e., Version="[6.0.0]")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the case of the build project it does not matter, but feel free to pin

<PackageReference Include="Fake.DotNet.Cli" Version="6.0.0" />
<PackageReference Include="Fake.DotNet.MSBuild" Version="6.0.0" />
<PackageReference Include="Fake.IO.FileSystem" Version="6.0.0" />
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
34 changes: 34 additions & 0 deletions src/FSharpAux.Core/Seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,40 @@ module Seq =
hsSs.IntersectWith largerSeq
hsSs

/// <summary>
/// Divides the input sequence into chunks by a key projection function.
///
/// A new chunk is created each time the projection function returns a new value, and the resulting chunks are tupled with their keys.
///
/// Example: Seq.chunkBy isOdd [3;3;2;4;1;2] = seq [(true, [3; 3]); (false, [2; 4]); (true, [1]); (false, [2])]
/// </summary>
/// <param name="projection">The function to determine if an element creates a new chunk</param>
/// <param name="source"></param>
let chunkBy (projection: 'T -> 'Key) (source: seq<'T>) =
seq {
use e = source.GetEnumerator ()
if e.MoveNext () then
// the key of the current chunk
let mutable chunkKey = projection e.Current
// the members of the current chunk
let mutable members = ResizeArray ()
members.Add e.Current

while e.MoveNext () do
let currentKey = projection e.Current
if chunkKey = currentKey then
// add item to current chunk if projection returns the chunk key again
members.Add e.Current
else
// yield current chunk and start a new one if projection returns a new key
yield chunkKey, members |> Seq.cast<'T>
chunkKey <- currentKey
members <- ResizeArray ()
members.Add e.Current

yield chunkKey, members |> Seq.cast<'T>
}

// // Without continuation passing

// let groupWhen f (input:seq<_>) = seq {
Expand Down
14 changes: 7 additions & 7 deletions tests/FSharpAux.Core.Tests/FSharpAux.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

Expand All @@ -17,15 +17,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fable.Mocha" Version="2.16.0" />
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="Fable.Mocha" Version="2.16.0" />
<PackageReference Include="Expecto" Version="10.*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.15.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FSharpAux.Core\FSharpAux.Core.fsproj" />
</ItemGroup>
Expand Down
37 changes: 27 additions & 10 deletions tests/FSharpAux.Core.Tests/SeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let private testSeq3 = seq {3; 3; 2; 4; 1; 1}
let private testSeq4 = seq {3; 3; 2; 4; 2; 2}
let private testSeq5 = seq {3; 3; 2; 4; 2; 1}
let private testSeq6 = seq {6; 6; 2; 4; 2; 8}
let private testSeq7 = seq {"2"; "A"; "A"; "B"; "B"; "C"; "D"}

let private testSeq2_groupWhen_Equal = seq {seq {3}; seq {3; 2; 4}; seq {1; 2}}
let private testSeq2_groupWhen_NotEqual = seq {seq {3}; seq {3; 2; 4}; seq {1}; seq {2}}
Expand All @@ -23,45 +24,61 @@ let private testSeq4_groupWhen_NotEqual = seq {seq {3}; seq {3; 2; 4; 2}
let private testSeq5_groupWhen_Equal = seq {seq {3}; seq {3; 2; 4; 2}; seq {1}}
let private testSeq5_groupWhen_NotEqual = seq {seq {3}; seq {3; 2; 4; 2; 1}}

let private testSeq2_chunkByIsOdd = seq {(true, seq {3; 3}); (false, seq {2; 4}); (true, seq {1}); (false, seq {2})}
let private testSeq6_chunkByIsOdd = seq {(false, seq {6; 6; 2; 4; 2; 8})}
let private testSeq7_chunkById = seq {("2", seq {"2"}); ("A", seq {"A"; "A"}); ("B", seq {"B"; "B"}); ("C", seq {"C"}); ("D", seq {"D"})}

// helper functions
let private list s = Seq.toList s
let private list2 s = Seq.map (Seq.toList) s |> Seq.toList
let private list2Tpl (s: seq<'Key*seq<'Items>>) = Seq.map (fun (k, i) -> k, i |> Seq.toList) s |> Seq.toList
let isOdd = fun n -> n % 2 <> 0

let seqTests =
testList "SeqTests" [
let isOdd = fun n -> n % 2 <> 0
testList "Seq.groupWhen" [
testCase "returns correct jagged list, case1: [3; 3; 2; 4; 1; 2]" (fun _ ->
Expect.equal (testSeq2 |> Seq.groupWhen isOdd |> list2) (testSeq2_groupWhen_Equal |> list2) "Seq.groupWhen did return correct jagged list"
Expect.equal (testSeq2 |> Seq.groupWhen isOdd |> list2) (testSeq2_groupWhen_Equal |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "does not return incorrect jagged list, case1: [3; 3; 2; 4; 1; 2]" (fun _ ->
Expect.notEqual (testSeq2 |> Seq.groupWhen isOdd |> list2) (testSeq2_groupWhen_NotEqual |> list2) "Seq.groupWhen did not return incorrect jagged list"
Expect.notEqual (testSeq2 |> Seq.groupWhen isOdd |> list2) (testSeq2_groupWhen_NotEqual |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "returns correct jagged list, case2: [3; 3; 2; 4; 1; 1]" (fun _ ->
Expect.equal (testSeq3 |> Seq.groupWhen isOdd |> list2) (testSeq3_groupWhen_Equal |> list2) "Seq.groupWhen did return correct jagged list"
Expect.equal (testSeq3 |> Seq.groupWhen isOdd |> list2) (testSeq3_groupWhen_Equal |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "does not return incorrect jagged list, case2: [3; 3; 2; 4; 1; 1]" (fun _ ->
Expect.notEqual (testSeq3 |> Seq.groupWhen isOdd |> list2) (testSeq3_groupWhen_NotEqual |> list2) "Seq.groupWhen did not return incorrect jagged list"
Expect.notEqual (testSeq3 |> Seq.groupWhen isOdd |> list2) (testSeq3_groupWhen_NotEqual |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "returns correct jagged list, case3: [3; 3; 2; 4; 2; 2]" (fun _ ->
Expect.equal (testSeq4 |> Seq.groupWhen isOdd |> list2) (testSeq4_groupWhen_Equal |> list2) "Seq.groupWhen did return correct jagged list"
Expect.equal (testSeq4 |> Seq.groupWhen isOdd |> list2) (testSeq4_groupWhen_Equal |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "does not return incorrect jagged list, case3: [3; 3; 2; 4; 2; 2]" (fun _ ->
Expect.notEqual (testSeq4 |> Seq.groupWhen isOdd |> list2) (testSeq4_groupWhen_NotEqual |> list2) "Seq.groupWhen did not return incorrect jagged list"
Expect.notEqual (testSeq4 |> Seq.groupWhen isOdd |> list2) (testSeq4_groupWhen_NotEqual |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "returns correct jagged list, case4: [3; 3; 2; 4; 2; 1]" (fun _ ->
Expect.equal (testSeq5 |> Seq.groupWhen isOdd |> list2) (testSeq5_groupWhen_Equal |> list2) "Seq.groupWhen did return correct jagged list"
Expect.equal (testSeq5 |> Seq.groupWhen isOdd |> list2) (testSeq5_groupWhen_Equal |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "does not return incorrect jagged list, case4: [3; 3; 2; 4; 2; 1]" (fun _ ->
Expect.notEqual (testSeq5 |> Seq.groupWhen isOdd |> list2) (testSeq5_groupWhen_NotEqual |> list2) "Seq.groupWhen did not return incorrect jagged list"
Expect.notEqual (testSeq5 |> Seq.groupWhen isOdd |> list2) (testSeq5_groupWhen_NotEqual |> list2) "Seq.groupWhen did return incorrect jagged list"
)
testCase "returns correct jagged list, case4: [6; 6; 2; 4; 2; 8]" (fun _ ->
Expect.equal (testSeq6 |> Seq.groupWhen isOdd |> list2) ([testSeq6 |> list]) "Seq.groupWhen did return correct jagged list"
Expect.equal (testSeq6 |> Seq.groupWhen isOdd |> list2) ([testSeq6 |> list]) "Seq.groupWhen did return incorrect jagged list"
)
testCase "does not return incorrect jagged list, case4: [6; 6; 2; 4; 2; 8]" (fun _ ->
Expect.notEqual (testSeq6 |> Seq.groupWhen isOdd |> list2) ([]) "Seq.groupWhen did not return empty (jagged) list"
)
]
testList "Seq.chunkBy" [
test "chunk integers by odd/even" {
Expect.equal (testSeq2 |> Seq.chunkBy isOdd |> list2Tpl) (testSeq2_chunkByIsOdd |> list2Tpl) "Seq.chunkBy did return incorrect jagged list"
}
test "chunk integers by odd/even only one chunk" {
Expect.equal (testSeq6 |> Seq.chunkBy isOdd |> list2Tpl) (testSeq6_chunkByIsOdd |> list2Tpl) "Seq.chunkBy did return incorrect jagged list"
}
test "chunk strings by id" {
Expect.equal (testSeq7 |> Seq.chunkBy id |> list2Tpl) (testSeq7_chunkById |> list2Tpl) "Seq.chunkBy did return incorrect jagged list"
}
]
testList "Seq.intersect" [
testCase "returns correct list, case1: []" (fun _ ->
Expect.equal (Seq.intersect Seq.empty Seq.empty |> list) [] "Seq.intersect did return correct list"
Expand Down
8 changes: 4 additions & 4 deletions tests/FSharpAux.IO.Tests/FSharpAux.IO.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

Expand All @@ -13,9 +13,9 @@
<ItemGroup>
<PackageReference Include="Deedle" Version="2.4.1" />
<PackageReference Include="FSharp.Data" Version="4.2.0" />
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="Expecto" Version="10.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.15.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions tests/FSharpAux.Tests/FSharpAux.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

Expand All @@ -17,11 +17,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="Expecto" Version="10.*" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.15.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FSharpAux\FSharpAux.fsproj" />
</ItemGroup>
Expand Down
Loading