From ba149dd7a6d37c62d85aa1c2a710a6f7066a46c8 Mon Sep 17 00:00:00 2001 From: Andrei Sergeev Date: Sat, 14 Aug 2021 11:47:26 +0300 Subject: [PATCH 1/2] v1.2.0-preview.1.0.0: Add typed Yielder --- .../YieldExtensionsTest.Single.cs | 4 +-- .../Linq/YielderTest/YielderTest.Single.cs | 4 +-- .../YielderTypedTest.Empty.cs | 18 +++++++++++ .../YielderTypedTest.Single.cs | 32 +++++++++++++++++++ .../Linq/YielderTypedTest/YielderTypedTest.cs | 8 +++++ .../Primitives.Tests/Primitives.Tests.csproj | 4 +-- .../Primitives.Tests/Primitives.Tests.sln | 25 +++++++++++++++ .../Primitives/Linq/YieldExtensions.cs | 4 ++- src/primitives/Primitives/Linq/Yielder.T.cs | 19 +++++++++++ src/primitives/Primitives/Linq/Yielder.cs | 13 ++++---- .../Pipeline/PipelineExtensions.Pipe.cs | 2 +- src/primitives/Primitives/Primitives.csproj | 2 +- src/primitives/Primitives/Primitives.sln | 25 +++++++++++++++ 13 files changed, 145 insertions(+), 15 deletions(-) create mode 100644 src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Empty.cs create mode 100644 src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Single.cs create mode 100644 src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.cs create mode 100644 src/primitives/Primitives.Tests/Primitives.Tests.sln create mode 100644 src/primitives/Primitives/Linq/Yielder.T.cs create mode 100644 src/primitives/Primitives/Primitives.sln diff --git a/src/primitives/Primitives.Tests/Linq/YieldExtensionsTest/YieldExtensionsTest.Single.cs b/src/primitives/Primitives.Tests/Linq/YieldExtensionsTest/YieldExtensionsTest.Single.cs index 41740d2d..4280e14f 100644 --- a/src/primitives/Primitives.Tests/Linq/YieldExtensionsTest/YieldExtensionsTest.Single.cs +++ b/src/primitives/Primitives.Tests/Linq/YieldExtensionsTest/YieldExtensionsTest.Single.cs @@ -10,7 +10,7 @@ partial class YieldExtensionsTest [Test] [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] public void YieldSingle_ExpectCollectionLengthEqualsOne( - in object? sourceValue) + object? sourceValue) { var actual = sourceValue.YieldSingle(); @@ -21,7 +21,7 @@ public void YieldSingle_ExpectCollectionLengthEqualsOne( [Test] [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] public void YieldSingle_ExpectFirstItemIsSameAsSourceValue( - in object? sourceValue) + object? sourceValue) { var actual = sourceValue.YieldSingle(); diff --git a/src/primitives/Primitives.Tests/Linq/YielderTest/YielderTest.Single.cs b/src/primitives/Primitives.Tests/Linq/YielderTest/YielderTest.Single.cs index 41680fca..e23bf63b 100644 --- a/src/primitives/Primitives.Tests/Linq/YielderTest/YielderTest.Single.cs +++ b/src/primitives/Primitives.Tests/Linq/YielderTest/YielderTest.Single.cs @@ -10,7 +10,7 @@ partial class YielderTest [Test] [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] public void YieldSingle_ExpectCollectionLengthEqualsOne( - in object? sourceValue) + object? sourceValue) { var actual = Yielder.YieldSingle(sourceValue); @@ -21,7 +21,7 @@ public void YieldSingle_ExpectCollectionLengthEqualsOne( [Test] [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] public void YieldSingle_ExpectFirstItemIsSameAsSourceValue( - in object? sourceValue) + object? sourceValue) { var actual = Yielder.YieldSingle(sourceValue); diff --git a/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Empty.cs b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Empty.cs new file mode 100644 index 00000000..67260ac5 --- /dev/null +++ b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Empty.cs @@ -0,0 +1,18 @@ +#nullable enable + +using NUnit.Framework; +using PrimeFuncPack.UnitTest; +using System.Linq; + +namespace PrimeFuncPack.Primitives.Tests +{ + partial class YielderTypedTest + { + [Test] + public void YieldEmpty_ExpectEmptyCollection() + { + var actual = Yielder.YieldEmpty(); + Assert.IsEmpty(actual); + } + } +} diff --git a/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Single.cs b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Single.cs new file mode 100644 index 00000000..4266fc43 --- /dev/null +++ b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.Single.cs @@ -0,0 +1,32 @@ +#nullable enable + +using NUnit.Framework; +using System.Linq; + +namespace PrimeFuncPack.Primitives.Tests +{ + partial class YielderTypedTest + { + [Test] + [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] + public void YieldSingle_ExpectCollectionLengthEqualsOne( + object? sourceValue) + { + var actual = Yielder.YieldSingle(sourceValue); + + var actualLength = actual.Count(); + Assert.AreEqual(1, actualLength); + } + + [Test] + [TestCaseSource(typeof(ObjectTestData), nameof(ObjectTestData.NullableObjectTestSource))] + public void YieldSingle_ExpectFirstItemIsSameAsSourceValue( + object? sourceValue) + { + var actual = Yielder.YieldSingle(sourceValue); + + var actualFirst = actual.FirstOrDefault(); + Assert.AreSame(sourceValue, actualFirst); + } + } +} diff --git a/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.cs b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.cs new file mode 100644 index 00000000..570d405a --- /dev/null +++ b/src/primitives/Primitives.Tests/Linq/YielderTypedTest/YielderTypedTest.cs @@ -0,0 +1,8 @@ +#nullable enable + +namespace PrimeFuncPack.Primitives.Tests +{ + public sealed partial class YielderTypedTest + { + } +} diff --git a/src/primitives/Primitives.Tests/Primitives.Tests.csproj b/src/primitives/Primitives.Tests/Primitives.Tests.csproj index 443f9fe8..170e15b6 100644 --- a/src/primitives/Primitives.Tests/Primitives.Tests.csproj +++ b/src/primitives/Primitives.Tests/Primitives.Tests.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/src/primitives/Primitives.Tests/Primitives.Tests.sln b/src/primitives/Primitives.Tests/Primitives.Tests.sln new file mode 100644 index 00000000..8bfb7e24 --- /dev/null +++ b/src/primitives/Primitives.Tests/Primitives.Tests.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31605.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Primitives.Tests", "Primitives.Tests.csproj", "{9293E3A1-8EA6-4BCB-8835-36E4F58E283A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B0DEAF30-2D78-493A-9FC4-283D7320836A} + EndGlobalSection +EndGlobal diff --git a/src/primitives/Primitives/Linq/YieldExtensions.cs b/src/primitives/Primitives/Linq/YieldExtensions.cs index f809a543..b9385e99 100644 --- a/src/primitives/Primitives/Linq/YieldExtensions.cs +++ b/src/primitives/Primitives/Linq/YieldExtensions.cs @@ -8,6 +8,8 @@ namespace System.Linq public static class YieldExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IEnumerable YieldSingle(this T value) => Yielder.YieldSingle(value); + public static IEnumerable YieldSingle(this T value) + => + Yielder.YieldSingle(value); } } diff --git a/src/primitives/Primitives/Linq/Yielder.T.cs b/src/primitives/Primitives/Linq/Yielder.T.cs new file mode 100644 index 00000000..d8c4bdff --- /dev/null +++ b/src/primitives/Primitives/Linq/Yielder.T.cs @@ -0,0 +1,19 @@ +#nullable enable + +using System.Collections.Generic; + +namespace System.Linq +{ + public static class Yielder + { + public static IEnumerable YieldSingle(T value) + { + yield return value; + } + + public static IEnumerable YieldEmpty() + { + yield break; + } + } +} diff --git a/src/primitives/Primitives/Linq/Yielder.cs b/src/primitives/Primitives/Linq/Yielder.cs index bc71dd17..d50279ce 100644 --- a/src/primitives/Primitives/Linq/Yielder.cs +++ b/src/primitives/Primitives/Linq/Yielder.cs @@ -1,19 +1,20 @@ #nullable enable using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace System.Linq { public static class Yielder { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable YieldSingle(T value) - { - yield return value; - } + => + Yielder.YieldSingle(value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable YieldEmpty() - { - yield break; - } + => + Yielder.YieldEmpty(); } } diff --git a/src/primitives/Primitives/Pipeline/PipelineExtensions.Pipe.cs b/src/primitives/Primitives/Pipeline/PipelineExtensions.Pipe.cs index 60d8ea4b..800a43d9 100644 --- a/src/primitives/Primitives/Pipeline/PipelineExtensions.Pipe.cs +++ b/src/primitives/Primitives/Pipeline/PipelineExtensions.Pipe.cs @@ -10,7 +10,7 @@ partial class PipelineExtensions public static TResult Pipe(this T value, Func pipe) { _ = pipe ?? throw new ArgumentNullException(nameof(pipe)); - + return pipe.Invoke(value); } } diff --git a/src/primitives/Primitives/Primitives.csproj b/src/primitives/Primitives/Primitives.csproj index aff78c37..c3acda10 100644 --- a/src/primitives/Primitives/Primitives.csproj +++ b/src/primitives/Primitives/Primitives.csproj @@ -11,7 +11,7 @@ Copyright © 2020-2021 Andrei Sergeev, Pavel Moskovoy System PrimeFuncPack.Primitives - 1.1.3 + 1.2.0-preview.1.0.0 diff --git a/src/primitives/Primitives/Primitives.sln b/src/primitives/Primitives/Primitives.sln new file mode 100644 index 00000000..90c5d15d --- /dev/null +++ b/src/primitives/Primitives/Primitives.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31605.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Primitives", "Primitives.csproj", "{B3AF0201-1473-4F53-B147-9BCA2711BA7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C9B32047-42F8-4E3F-B42C-482B0FA1EB7E} + EndGlobalSection +EndGlobal From 70515eedbffb90e6c3793b50f4e2972e086ee497 Mon Sep 17 00:00:00 2001 From: Andrei Sergeev Date: Sat, 14 Aug 2021 11:48:07 +0300 Subject: [PATCH 2/2] Remove sln files --- .../Primitives.Tests/Primitives.Tests.sln | 25 ------------------- src/primitives/Primitives/Primitives.sln | 25 ------------------- 2 files changed, 50 deletions(-) delete mode 100644 src/primitives/Primitives.Tests/Primitives.Tests.sln delete mode 100644 src/primitives/Primitives/Primitives.sln diff --git a/src/primitives/Primitives.Tests/Primitives.Tests.sln b/src/primitives/Primitives.Tests/Primitives.Tests.sln deleted file mode 100644 index 8bfb7e24..00000000 --- a/src/primitives/Primitives.Tests/Primitives.Tests.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31605.320 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Primitives.Tests", "Primitives.Tests.csproj", "{9293E3A1-8EA6-4BCB-8835-36E4F58E283A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9293E3A1-8EA6-4BCB-8835-36E4F58E283A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B0DEAF30-2D78-493A-9FC4-283D7320836A} - EndGlobalSection -EndGlobal diff --git a/src/primitives/Primitives/Primitives.sln b/src/primitives/Primitives/Primitives.sln deleted file mode 100644 index 90c5d15d..00000000 --- a/src/primitives/Primitives/Primitives.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31605.320 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Primitives", "Primitives.csproj", "{B3AF0201-1473-4F53-B147-9BCA2711BA7D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B3AF0201-1473-4F53-B147-9BCA2711BA7D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {C9B32047-42F8-4E3F-B42C-482B0FA1EB7E} - EndGlobalSection -EndGlobal