Skip to content

Commit

Permalink
Merge pull request #19 from pfpack/release/v1.2.0-preview.1.0.0
Browse files Browse the repository at this point in the history
release/v1.2.0-preview.1.0.0
  • Loading branch information
pmosk authored Aug 14, 2021
2 parents 7cabf94 + 70515ee commit db70d85
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<StructType?>.YieldEmpty();
Assert.IsEmpty(actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<object?>.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<object?>.YieldSingle(sourceValue);

var actualFirst = actual.FirstOrDefault();
Assert.AreSame(sourceValue, actualFirst);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#nullable enable

namespace PrimeFuncPack.Primitives.Tests
{
public sealed partial class YielderTypedTest
{
}
}
4 changes: 2 additions & 2 deletions src/primitives/Primitives.Tests/Primitives.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="PrimeFuncPack.Primitives" Version="1.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="PrimeFuncPack.Primitives" Version="1.2.0-preview.1.0.0" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="2.0.6" />
</ItemGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/primitives/Primitives/Linq/YieldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace System.Linq
public static class YieldExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<T> YieldSingle<T>(this T value) => Yielder.YieldSingle(value);
public static IEnumerable<T> YieldSingle<T>(this T value)
=>
Yielder<T>.YieldSingle(value);
}
}
19 changes: 19 additions & 0 deletions src/primitives/Primitives/Linq/Yielder.T.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#nullable enable

using System.Collections.Generic;

namespace System.Linq
{
public static class Yielder<T>
{
public static IEnumerable<T> YieldSingle(T value)
{
yield return value;
}

public static IEnumerable<T> YieldEmpty()
{
yield break;
}
}
}
13 changes: 7 additions & 6 deletions src/primitives/Primitives/Linq/Yielder.cs
Original file line number Diff line number Diff line change
@@ -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<T> YieldSingle<T>(T value)
{
yield return value;
}
=>
Yielder<T>.YieldSingle(value);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<T> YieldEmpty<T>()
{
yield break;
}
=>
Yielder<T>.YieldEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ partial class PipelineExtensions
public static TResult Pipe<T, TResult>(this T value, Func<T, TResult> pipe)
{
_ = pipe ?? throw new ArgumentNullException(nameof(pipe));

return pipe.Invoke(value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/Primitives/Primitives.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Copyright>Copyright © 2020-2021 Andrei Sergeev, Pavel Moskovoy</Copyright>
<RootNamespace>System</RootNamespace>
<AssemblyName>PrimeFuncPack.Primitives</AssemblyName>
<Version>1.1.3</Version>
<Version>1.2.0-preview.1.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit db70d85

Please sign in to comment.