Skip to content

Commit aa1e9d2

Browse files
Remove morelinq (#1180)
* Remove morelinq * undo
1 parent c246e74 commit aa1e9d2

File tree

10 files changed

+156
-34
lines changed

10 files changed

+156
-34
lines changed

Directory.Packages.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
2626
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
2727
<PackageVersion Include="Moq" Version="4.20.72" />
28-
<PackageVersion Include="morelinq" Version="3.4.2" />
2928
<PackageVersion Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="161.9135.0" />
3029
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
3130
<PackageVersion Include="System.Runtime.Caching" Version="8.0.1" />

performance/packages.lock.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,7 @@
17921792
"Microsoft.SqlServer.TransactSql.ScriptDom": "[161.9135.0, )",
17931793
"Newtonsoft.Json": "[13.0.3, )",
17941794
"System.Runtime.Caching": "[8.0.1, )",
1795-
"System.Security.AccessControl": "[6.0.1, )",
1796-
"morelinq": "[3.4.2, )"
1795+
"System.Security.AccessControl": "[6.0.1, )"
17971796
}
17981797
},
17991798
"microsoft.azure.webjobs.extensions.sql.samples": {
@@ -2044,12 +2043,6 @@
20442043
"Castle.Core": "5.1.1"
20452044
}
20462045
},
2047-
"morelinq": {
2048-
"type": "CentralTransitive",
2049-
"requested": "[3.4.2, )",
2050-
"resolved": "3.4.2",
2051-
"contentHash": "nKdpt7Ai+xQO8PZ0YFTn13INGJcKO0Nx65kO/ut0zaDirRo6d7atedmW2l68YB3x7U4pOqTLdMfYsBys8KxA1Q=="
2052-
},
20532046
"Newtonsoft.Json": {
20542047
"type": "CentralTransitive",
20552048
"requested": "[13.0.3, )",

samples/samples-csharp/packages.lock.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,8 +1666,7 @@
16661666
"Microsoft.SqlServer.TransactSql.ScriptDom": "[161.9135.0, )",
16671667
"Newtonsoft.Json": "[13.0.3, )",
16681668
"System.Runtime.Caching": "[8.0.1, )",
1669-
"System.Security.AccessControl": "[6.0.1, )",
1670-
"morelinq": "[3.4.2, )"
1669+
"System.Security.AccessControl": "[6.0.1, )"
16711670
}
16721671
},
16731672
"Microsoft.ApplicationInsights": {
@@ -1783,12 +1782,6 @@
17831782
"resolved": "161.9135.0",
17841783
"contentHash": "Ayubg3Qijaysyn/fJ0QMhv+ADTl5+nPcqE2KsvcIlMZGmSSRAKMxApVf947bLWNRmBIr2TlAS8cSA+cFQUZz1g=="
17851784
},
1786-
"morelinq": {
1787-
"type": "CentralTransitive",
1788-
"requested": "[3.4.2, )",
1789-
"resolved": "3.4.2",
1790-
"contentHash": "nKdpt7Ai+xQO8PZ0YFTn13INGJcKO0Nx65kO/ut0zaDirRo6d7atedmW2l68YB3x7U4pOqTLdMfYsBys8KxA1Q=="
1791-
},
17921785
"System.Runtime.Caching": {
17931786
"type": "CentralTransitive",
17941787
"requested": "[8.0.1, )",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace Microsoft.Azure.WebJobs.Extensions.Sql.Common
9+
{
10+
public static class IEnumerableExtensions
11+
{
12+
/// <summary>
13+
/// Batches the source sequence into sized buckets and applies a projection to each bucket.
14+
/// </summary>
15+
/// <typeparam name="TSource">Type of elements in <paramref name="source"/> sequence.</typeparam>
16+
/// <param name="source">The source sequence.</param>
17+
/// <param name="size">Size of buckets.</param>
18+
public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(
19+
this IEnumerable<TSource> source, int size)
20+
{
21+
if (source == null)
22+
{
23+
throw new ArgumentNullException(nameof(source));
24+
}
25+
26+
if (size <= 0)
27+
{
28+
throw new ArgumentOutOfRangeException(nameof(size));
29+
}
30+
31+
TSource[] bucket = null;
32+
int count = 0;
33+
34+
foreach (TSource item in source)
35+
{
36+
if (bucket == null)
37+
{
38+
bucket = new TSource[size];
39+
}
40+
41+
bucket[count++] = item;
42+
if (count != size)
43+
{
44+
continue;
45+
}
46+
47+
yield return bucket;
48+
49+
bucket = null;
50+
count = 0;
51+
}
52+
53+
if (bucket != null && count > 0)
54+
{
55+
yield return bucket.Take(count).ToArray();
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Returns a specified number of contiguous elements from the end of
61+
/// a sequence.
62+
/// </summary>
63+
/// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
64+
/// <param name="source">The sequence to return the last element of.</param>
65+
/// <param name="count">The number of elements to return.</param>
66+
/// <returns>
67+
/// An <see cref="IEnumerable{T}"/> that contains the specified number of
68+
/// elements from the end of the input sequence.
69+
/// </returns>
70+
public static IEnumerable<TSource> TakeLast<TSource>(this IEnumerable<TSource> source, int count)
71+
{
72+
if (source == null)
73+
{
74+
throw new ArgumentNullException(nameof(source));
75+
}
76+
77+
return source.Skip(Math.Max(0, source.Count() - count));
78+
}
79+
}
80+
}

src/Microsoft.Azure.WebJobs.Extensions.Sql.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<PackageReference Include="Microsoft.Data.SqlClient" />
2323
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
2424
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" />
25-
<PackageReference Include="morelinq" />
2625
<PackageReference Include="System.Runtime.Caching" />
2726
<!-- This isn't directly needed, but pinning it to v6 since v5 is deprecated and our transitive dependencies currently only ask for v5 -->
2827
<PackageReference Include="System.Security.AccessControl" />

src/SqlAsyncCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Data.SqlClient;
1515
using Microsoft.Extensions.Configuration;
1616
using Microsoft.Extensions.Logging;
17-
using MoreLinq;
1817
using Newtonsoft.Json;
1918
using Newtonsoft.Json.Serialization;
2019
using Microsoft.Azure.WebJobs.Extensions.Sql.Telemetry;
@@ -23,6 +22,7 @@
2322
using static Microsoft.Azure.WebJobs.Extensions.Sql.SqlBindingConstants;
2423
using static Microsoft.Azure.WebJobs.Extensions.Sql.SqlBindingUtilities;
2524
using static Microsoft.Azure.WebJobs.Extensions.Sql.Telemetry.Telemetry;
25+
using Microsoft.Azure.WebJobs.Extensions.Sql.Common;
2626

2727
namespace Microsoft.Azure.WebJobs.Extensions.Sql
2828
{

src/TriggerBinding/SqlTriggerScaleMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using static Microsoft.Azure.WebJobs.Extensions.Sql.Telemetry.Telemetry;
1010
using Microsoft.Azure.WebJobs.Host.Scale;
1111
using Microsoft.Extensions.Logging;
12-
using MoreLinq;
12+
using Microsoft.Azure.WebJobs.Extensions.Sql.Common;
1313

1414
namespace Microsoft.Azure.WebJobs.Extensions.Sql
1515
{

src/packages.lock.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@
115115
"resolved": "161.9135.0",
116116
"contentHash": "Ayubg3Qijaysyn/fJ0QMhv+ADTl5+nPcqE2KsvcIlMZGmSSRAKMxApVf947bLWNRmBIr2TlAS8cSA+cFQUZz1g=="
117117
},
118-
"morelinq": {
119-
"type": "Direct",
120-
"requested": "[3.4.2, )",
121-
"resolved": "3.4.2",
122-
"contentHash": "nKdpt7Ai+xQO8PZ0YFTn13INGJcKO0Nx65kO/ut0zaDirRo6d7atedmW2l68YB3x7U4pOqTLdMfYsBys8KxA1Q=="
123-
},
124118
"NETStandard.Library": {
125119
"type": "Direct",
126120
"requested": "[2.0.3, )",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.Azure.WebJobs.Extensions.Sql.Common;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using Xunit;
9+
10+
namespace Microsoft.Azure.WebJobs.Extensions.Sql.Tests.Unit
11+
{
12+
public class IEnumerableExtensionsTests
13+
{
14+
public static readonly TheoryData<int[], int> BatchData = new()
15+
{
16+
{ new int[] { 1, 2, 3, 4, 5 }, 1 }, // One by one
17+
{ new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 3 }, // Bigger non-single batch
18+
{ new int[] { 1, 2, 3, 4, 5 } , 5 }, // All one batch
19+
{ new int[] { 1 }, 2 }, // Batch size greater than array
20+
};
21+
22+
[Theory]
23+
[MemberData(nameof(BatchData))]
24+
public void Batch(IEnumerable<int> array, int batchSize)
25+
{
26+
int totalCount = 0;
27+
foreach (IEnumerable<int> batch in array.Batch(batchSize))
28+
{
29+
int batchCount = batch.Count();
30+
totalCount += batchCount;
31+
Assert.True(batch.Count() <= batchSize);
32+
}
33+
Assert.Equal(totalCount, array.Count());
34+
}
35+
36+
[Fact]
37+
public void Batch_Invalid()
38+
{
39+
// Array must be non-null
40+
Assert.ThrowsAny<Exception>(() => IEnumerableExtensions.Batch<int>(null, 0).Count());
41+
42+
// Size must be >= 1
43+
Assert.ThrowsAny<Exception>(() => IEnumerableExtensions.Batch(new int[] { 1, 2, 3 }, 0).Count());
44+
Assert.ThrowsAny<Exception>(() => IEnumerableExtensions.Batch(new int[] { 1, 2, 3 }, -1).Count());
45+
}
46+
47+
public static readonly TheoryData<int[], int, int[]> TakeLastData = new()
48+
{
49+
{ new int[] { 1, 2, 3, 4, 5 }, 1 , new int[] { 5 } }, // Take only last number
50+
{ new int[] { 1, 2, 3, 4, 5 }, 3 , new int[] { 3, 4, 5 } }, // Take some middle set of numbers
51+
{ new int[] { 1, 2, 3, 4, 5 }, 6 , new int[] { 1, 2, 3, 4, 5 } }, // Take more than exists in array
52+
{ new int[] { 1, 2, 3, 4, 5 }, 0 , Array.Empty<int>() }, // No numbers
53+
{ new int[] { 1, 2, 3, 4, 5 }, 0 , Array.Empty<int>() }, // Negative numbers (returns empty)
54+
};
55+
56+
[Theory]
57+
[MemberData(nameof(TakeLastData))]
58+
public void TakeLast(IEnumerable<int> array, int takeCount, IEnumerable<int> expectedValues)
59+
{
60+
IEnumerable<int> taken = IEnumerableExtensions.TakeLast(array, takeCount);
61+
Assert.Equal(taken, expectedValues);
62+
}
63+
64+
[Fact]
65+
public void TakeLast_Invalid()
66+
{
67+
// IEnumerable must be non-null
68+
Assert.ThrowsAny<Exception>(() => { IEnumerableExtensions.TakeLast<int>(null, 0); });
69+
}
70+
}
71+
}

test/packages.lock.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,7 @@
18151815
"Microsoft.SqlServer.TransactSql.ScriptDom": "[161.9135.0, )",
18161816
"Newtonsoft.Json": "[13.0.3, )",
18171817
"System.Runtime.Caching": "[8.0.1, )",
1818-
"System.Security.AccessControl": "[6.0.1, )",
1819-
"morelinq": "[3.4.2, )"
1818+
"System.Security.AccessControl": "[6.0.1, )"
18201819
}
18211820
},
18221821
"microsoft.azure.webjobs.extensions.sql.samples": {
@@ -1924,12 +1923,6 @@
19241923
"resolved": "161.9135.0",
19251924
"contentHash": "Ayubg3Qijaysyn/fJ0QMhv+ADTl5+nPcqE2KsvcIlMZGmSSRAKMxApVf947bLWNRmBIr2TlAS8cSA+cFQUZz1g=="
19261925
},
1927-
"morelinq": {
1928-
"type": "CentralTransitive",
1929-
"requested": "[3.4.2, )",
1930-
"resolved": "3.4.2",
1931-
"contentHash": "nKdpt7Ai+xQO8PZ0YFTn13INGJcKO0Nx65kO/ut0zaDirRo6d7atedmW2l68YB3x7U4pOqTLdMfYsBys8KxA1Q=="
1932-
},
19331926
"System.Runtime.Caching": {
19341927
"type": "CentralTransitive",
19351928
"requested": "[8.0.1, )",

0 commit comments

Comments
 (0)