Skip to content

Commit c0d20bb

Browse files
committed
Merge branch 'master' of https://github.com/sideeffffect/FSharpx.Extras into v2
# Conflicts: # build.fsx # tests/FSharpx.Tests/JSON.Equality.Tests.fs # tests/FSharpx.Tests/JSON.Serialization.Tests.fs # tests/FSharpx.Tests/JSON.Tests.fs # tests/FSharpx.Tests/JSON.XMLConversion.Tests.fs # tests/FSharpx.Tests/LinqExpression.Tests.fs # tests/FSharpx.Text.StructuredFormat.Tests/FSharpx.Text.StructuredFormat.Tests.fsproj
2 parents 73e2d39 + 10af18a commit c0d20bb

12 files changed

Lines changed: 91 additions & 25 deletions

File tree

FSharpx.Extras.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{50709973-279A-4DF0-AF26-8C7535C7C9AE}"
77
ProjectSection(SolutionItems) = preProject
88
paket.dependencies = paket.dependencies
9+
paket.lock = paket.lock
910
EndProjectSection
1011
EndProject
1112
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{722621A6-FA45-4129-8B8D-94880DCD7971}"
@@ -17,6 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1718
docs\content\index.fsx = docs\content\index.fsx
1819
LICENSE.md = LICENSE.md
1920
README.md = README.md
21+
src\FSharpx.Extras\FSharpx.Extras.paket.template = src\FSharpx.Extras\FSharpx.Extras.paket.template
22+
src\FSharpx.Text.StructuredFormat\FSharpx.Text.StructuredFormat.paket.template = src\FSharpx.Text.StructuredFormat\FSharpx.Text.StructuredFormat.paket.template
23+
.gitignore = .gitignore
2024
EndProjectSection
2125
EndProject
2226
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpx.Tests", "tests\FSharpx.Tests\FSharpx.Tests.fsproj", "{26D9D3EE-E882-43E6-A79E-5D1D89E92C4F}"

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build_script:
2-
- cmd: build.cmd
2+
- cmd: build.cmd CI
33
test: off
44
version: 0.0.1.{build}
55
artifacts:

build.fsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ let buildLibParams fxVersion =
5050
]
5151

5252
// targets
53-
Target "Clean" (fun _ ->
54-
CleanDirs [buildDir]
53+
Target "Clean" (fun _ ->
54+
for fxVersion in fxVersions do
55+
!! "*.sln"
56+
|> MSBuild (buildDirVer fxVersion) "Clean"(["Configuration","Release"] @ buildLibParams fxVersion)
57+
|> ignore
58+
CleanDirs [buildDir; packagesDir; "docs/output"]
5559
)
5660

5761

@@ -81,7 +85,7 @@ Target "Build" (fun _ ->
8185
for fxVersion in fxVersions do
8286
// Only generate tests for net40
8387
!! "*.sln"
84-
|> MSBuild (buildDirVer fxVersion) "Rebuild" (["Configuration","Release"] @ buildLibParams fxVersion)
88+
|> MSBuild (buildDirVer fxVersion) "Build" (["Configuration","Release"] @ buildLibParams fxVersion)
8589
|> ignore)
8690

8791
Target "Test" (fun _ ->
@@ -112,7 +116,7 @@ Target "GenerateDocs" (fun _ ->
112116
// Release Scripts
113117

114118
Target "ReleaseDocs" (fun _ ->
115-
let tempDocsDir = "temp/gh-pages"
119+
let tempDocsDir = "bin/gh-pages"
116120
if not (Directory.Exists tempDocsDir) then
117121
Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
118122

@@ -133,8 +137,7 @@ Target "Release" DoNothing
133137
Target "CI" DoNothing
134138

135139
// Build order
136-
"Clean"
137-
==> "AssemblyInfo"
140+
"AssemblyInfo"
138141
==> "Build"
139142
==> "Test"
140143

docs/tools/generate.fsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@ let info =
2222
// For typical project, no changes are needed below
2323
// --------------------------------------------------------------------------------------
2424

25+
#load "../../packages/FSharp.Formatting/FSharp.Formatting.fsx"
2526
#I "../../packages/FAKE/tools/"
26-
#I "../../packages/FSharp.Formatting/lib/net40"
27-
#I "../../packages/RazorEngine/lib/net40"
28-
#I "../../packages/FSharp.Compiler.Service/lib/net40"
29-
#r "../../packages/Microsoft.AspNet.Razor/lib/net40/System.Web.Razor.dll"
30-
#r "../../packages/FAKE/tools/FakeLib.dll"
31-
#r "RazorEngine.dll"
32-
#r "FSharp.Literate.dll"
33-
#r "FSharp.CodeFormat.dll"
34-
#r "FSharp.MetadataFormat.dll"
27+
#r "FakeLib.dll"
3528
open Fake
3629
open System.IO
3730
open Fake.FileHelper
@@ -47,7 +40,7 @@ let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output")
4740
#endif
4841

4942
// Paths with template/source/output locations
50-
let bin = __SOURCE_DIRECTORY__ @@ "../../bin/v4.0"
43+
let bin = __SOURCE_DIRECTORY__ @@ "../../bin/v4.5"
5144
let content = __SOURCE_DIRECTORY__ @@ "../content"
5245
let output = __SOURCE_DIRECTORY__ @@ "../output"
5346
let files = __SOURCE_DIRECTORY__ @@ "../files"
@@ -77,7 +70,9 @@ let buildReference () =
7770
sourceRepo = githubLink @@ "tree/master",
7871
sourceFolder = __SOURCE_DIRECTORY__ @@ ".." @@ "..",
7972
publicOnly = true,
80-
otherFlags=["-r:" + bin @@ "FSharpx.Collections.dll"] )
73+
otherFlags=["-r:" + bin @@ "FSharpx.Collections.dll"]
74+
, xmlFile = __SOURCE_DIRECTORY__ @@ "../../bin/FSharpx.Extras.xml"
75+
)
8176

8277
// Build documentation from `fsx` and `md` files in `docs/content`
8378
let buildDocumentation () =

src/FSharpx.Extras/ComputationExpressions/Monad.fs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,15 @@ module Task =
997997

998998
/// Sequence actions, discarding the value of the second argument.
999999
let inline ( <*) a b = lift2 (fun z _ -> z) a b
1000+
1001+
let foldM f s =
1002+
Seq.fold (fun acc t -> acc >>= (flip f) t) (returnM s)
1003+
1004+
let inline sequence (s:Task<'a> list) =
1005+
let inline cons a b = lift2 List.cons a b
1006+
List.foldBack cons s (returnM [])
1007+
1008+
let inline mapM f x = sequence (List.map f x)
10001009

10011010
type TaskBuilder(?continuationOptions, ?scheduler, ?cancellationToken) =
10021011
let contOptions = defaultArg continuationOptions TaskContinuationOptions.None
@@ -1043,6 +1052,8 @@ module Task =
10431052

10441053
member this.Run (f: unit -> Task<'T>) = f()
10451054

1055+
let task = TaskBuilder()
1056+
10461057
type TaskBuilderWithToken(?continuationOptions, ?scheduler) =
10471058
let contOptions = defaultArg continuationOptions TaskContinuationOptions.None
10481059
let scheduler = defaultArg scheduler TaskScheduler.Default
@@ -1085,3 +1096,47 @@ module Task =
10851096

10861097
member this.Delay f = this.Bind(this.Return (), f)
10871098

1099+
/// Converts a Task into Task<unit>
1100+
let ToTaskUnit (t:Task) =
1101+
let continuation _ = ()
1102+
t.ContinueWith continuation
1103+
1104+
/// Creates a task that runs the given task and ignores its result.
1105+
let inline Ignore t = bind (fun _ -> returnM ()) t
1106+
1107+
/// Creates a task that executes a specified task.
1108+
/// If this task completes successfully, then this function returns Choice1Of2 with the returned value.
1109+
/// If this task raises an exception before it completes then return Choice2Of2 with the raised exception.
1110+
let Catch (t:Task<'a>) =
1111+
task {
1112+
try let! r = t
1113+
return Choice1Of2 r
1114+
with e ->
1115+
return Choice2Of2 e
1116+
}
1117+
1118+
#if !NET40
1119+
/// Creates a task that executes all the given tasks.
1120+
let Parallel (tasks : seq<unit -> Task<'a>>) =
1121+
tasks
1122+
|> Seq.map (fun t -> t())
1123+
|> Array.ofSeq
1124+
|> Task.WhenAll
1125+
1126+
/// Creates a task that executes all the given tasks.
1127+
/// The paralelism is throttled, so that at most `throttle` tasks run at one time.
1128+
let ParallelWithTrottle throttle (tasks : seq<unit -> Task<'a>>) : (Task<'a[]>) =
1129+
let semaphore = new SemaphoreSlim(throttle)
1130+
let throttleTask (t:unit->Task<'a>) () : Task<'a> =
1131+
task {
1132+
do! semaphore.WaitAsync() |> ToTaskUnit
1133+
let! result = Catch <| t()
1134+
semaphore.Release() |> ignore
1135+
return match result with
1136+
| Choice1Of2 r -> r
1137+
| Choice2Of2 e -> raise e
1138+
}
1139+
tasks
1140+
|> Seq.map throttleTask
1141+
|> Parallel
1142+
#endif

src/FSharpx.Extras/FSharpx.Extras.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
</PropertyGroup>
5656
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
5757
<ItemGroup>
58+
<Content Include="paket.references" />
59+
<Content Include="app.config" />
5860
<Compile Include="AssemblyInfo.fs" />
5961
<Compile Include="Prelude.fs" />
6062
<Compile Include="Pluralizer.fs" />
@@ -73,8 +75,6 @@
7375
<Compile Include="Stm.fs" />
7476
<Compile Include="Iteratee.fs" />
7577
<Compile Include="CSharpCompat.fs" />
76-
<Content Include="paket.references" />
77-
<Content Include="app.config" />
7878
<Compile Include="Net.fs" />
7979
<Compile Include="Conneg.fs" />
8080
<Compile Include="Enum.fs" />

src/FSharpx.Extras/FSharpx.Extras.paket.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ dependencies
2929
FSharpx.Async ~> LOCKEDVERSION
3030
FSharpx.Collections ~> LOCKEDVERSION
3131
files
32-
../../bin/v4.0/FSharpx.Extras.dll ==> lib/40
33-
../../bin/FSharpx.Extras.xml ==> lib/40
32+
../../bin/v4.5/FSharpx.Extras.dll ==> lib/net45
33+
../../bin/FSharpx.Extras.xml ==> lib/net45
3434
../../LICENSE.md ==> .

src/FSharpx.Text.StructuredFormat/FSharpx.Text.StructuredFormat.paket.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ dependencies
2525
FSharpx.Collections ~> LOCKEDVERSION
2626
FSharpx.Extras = CURRENTVERSION
2727
files
28-
../../bin/v4.0/FSharpx.Text.StructuredFormat.dll ==> lib/40
29-
bin/Release/FSharpx.Text.StructuredFormat.xml ==> lib/40
28+
../../bin/v4.5/FSharpx.Text.StructuredFormat.dll ==> lib/net45
29+
bin/Release/FSharpx.Text.StructuredFormat.xml ==> lib/net45
3030
../../LICENSE.md ==> .

tests/FSharpx.CSharpTests/AsyncTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using Microsoft.FSharp.Core;
1212
using NUnit.Framework;
1313

14+
#pragma warning disable 219
15+
1416
namespace FSharpx.CSharpTests {
1517
[TestFixture]
1618
public class AsyncTests {

tests/FSharpx.CSharpTests/FuncTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public void FromActionEta() {
1919
int a = 0;
2020
Action action = () => a = a + 1;
2121
Action[] actions = new[] {action,action};
22+
#pragma warning disable 219
2223
var functions = actions.Select(FSharpFunc.FromAction);
24+
#pragma warning restore 219
25+
2326
}
2427

2528
[Test]

0 commit comments

Comments
 (0)