From e37d00695046d96795ea505ba494890bfc5a33bd Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Mon, 13 Nov 2023 11:46:28 -0600 Subject: [PATCH] Remove Invalid `Share` overload --- .../PublicAPI/net6.0/PublicAPI.Unshipped.txt | 1 + .../PublicAPI/net7.0/PublicAPI.Unshipped.txt | 1 + .../PublicAPI/net8.0/PublicAPI.Unshipped.txt | 1 + .../netcoreapp3.1/PublicAPI.Unshipped.txt | 1 + Source/SuperLinq.Async/Share.cs | 32 ------------------- .../PublicAPI/net6.0/PublicAPI.Unshipped.txt | 1 + .../PublicAPI/net7.0/PublicAPI.Unshipped.txt | 1 + .../PublicAPI/net8.0/PublicAPI.Unshipped.txt | 1 + .../netcoreapp3.1/PublicAPI.Unshipped.txt | 1 + Source/SuperLinq/Share.cs | 27 ---------------- Tests/SuperLinq.Async.Test/ShareTest.cs | 15 --------- Tests/SuperLinq.Test/ShareTest.cs | 15 --------- 12 files changed, 8 insertions(+), 89 deletions(-) diff --git a/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 73b491b52..bdc6e2412 100644 --- a/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Func!, System.Collections.Generic.IAsyncEnumerable!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable! True, System.Collections.Generic.IAsyncEnumerable! False)> *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! +*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! diff --git a/Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt index 73b491b52..bdc6e2412 100644 --- a/Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Func!, System.Collections.Generic.IAsyncEnumerable!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable! True, System.Collections.Generic.IAsyncEnumerable! False)> *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! +*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! diff --git a/Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 73b491b52..bdc6e2412 100644 --- a/Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Func!, System.Collections.Generic.IAsyncEnumerable!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable! True, System.Collections.Generic.IAsyncEnumerable! False)> *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! +*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! diff --git a/Source/SuperLinq.Async/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt b/Source/SuperLinq.Async/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt index 73b491b52..bdc6e2412 100644 --- a/Source/SuperLinq.Async/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq.Async/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Func!, System.Collections.Generic.IAsyncEnumerable!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition(this System.Collections.Generic.IAsyncEnumerable! source, System.Func! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable! True, System.Collections.Generic.IAsyncEnumerable! False)> *REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! +*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share(this System.Collections.Generic.IAsyncEnumerable! source, System.Func!, System.Collections.Generic.IAsyncEnumerable!>! selector) -> System.Collections.Generic.IAsyncEnumerable! diff --git a/Source/SuperLinq.Async/Share.cs b/Source/SuperLinq.Async/Share.cs index d451a1e9a..abe14e904 100644 --- a/Source/SuperLinq.Async/Share.cs +++ b/Source/SuperLinq.Async/Share.cs @@ -19,38 +19,6 @@ public static IAsyncBuffer Share(this IAsyncEnumerable(source); } - /// - /// Shares the source sequence within a selector function where each enumerator can fetch the next element from the - /// source sequence. - /// - /// Source sequence element type. - /// Result sequence element type. - /// Source sequence. - /// Selector function with shared access to the source sequence for each enumerator. - /// Sequence resulting from applying the selector function to the shared view over the source - /// sequence. - /// or is . - public static IAsyncEnumerable Share( - this IAsyncEnumerable source, - Func, IAsyncEnumerable> selector) - { - Guard.IsNotNull(source); - Guard.IsNotNull(selector); - - return Core(source, selector); - - static async IAsyncEnumerable Core( - IAsyncEnumerable source, - Func, IAsyncEnumerable> selector, - [EnumeratorCancellation] CancellationToken cancellationToken = default) - { - await using var buffer = source.Share(); - await foreach (var i in selector(buffer).WithCancellation(cancellationToken).ConfigureAwait(false)) - yield return i; - } - } - private sealed class SharedBuffer : IAsyncBuffer { private readonly SemaphoreSlim _lock = new(initialCount: 1); diff --git a/Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 30eeb0bde..e72585ec0 100644 --- a/Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt @@ -2,3 +2,4 @@ static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, System.Func! seedSelector, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, TAccumulate seed, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! *REMOVED*static SuperLinq.SuperEnumerable.Publish(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! +*REMOVED*static SuperLinq.SuperEnumerable.Share(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! diff --git a/Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt index 30eeb0bde..e72585ec0 100644 --- a/Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -2,3 +2,4 @@ static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, System.Func! seedSelector, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, TAccumulate seed, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! *REMOVED*static SuperLinq.SuperEnumerable.Publish(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! +*REMOVED*static SuperLinq.SuperEnumerable.Share(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! diff --git a/Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 30eeb0bde..e72585ec0 100644 --- a/Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -2,3 +2,4 @@ static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, System.Func! seedSelector, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, TAccumulate seed, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! *REMOVED*static SuperLinq.SuperEnumerable.Publish(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! +*REMOVED*static SuperLinq.SuperEnumerable.Share(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! diff --git a/Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt b/Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt index 30eeb0bde..e72585ec0 100644 --- a/Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt +++ b/Source/SuperLinq/PublicAPI/netcoreapp3.1/PublicAPI.Unshipped.txt @@ -2,3 +2,4 @@ static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, System.Func! seedSelector, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! static SuperLinq.SuperEnumerable.AggregateBy(this System.Collections.Generic.IEnumerable! source, System.Func! keySelector, TAccumulate seed, System.Func! func, System.Collections.Generic.IEqualityComparer? comparer = null) -> System.Collections.Generic.IEnumerable>! *REMOVED*static SuperLinq.SuperEnumerable.Publish(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! +*REMOVED*static SuperLinq.SuperEnumerable.Share(this System.Collections.Generic.IEnumerable! source, System.Func!, System.Collections.Generic.IEnumerable!>! selector) -> System.Collections.Generic.IEnumerable! diff --git a/Source/SuperLinq/Share.cs b/Source/SuperLinq/Share.cs index fcf21da5b..ef02c4d29 100644 --- a/Source/SuperLinq/Share.cs +++ b/Source/SuperLinq/Share.cs @@ -35,33 +35,6 @@ public static IBuffer Share(this IEnumerable source) return new SharedBuffer(source); } - /// - /// Shares the source sequence within a selector function where each enumerator can fetch the next element from the - /// source sequence. - /// - /// Source sequence element type. - /// Result sequence element type. - /// Source sequence. - /// Selector function with shared access to the source sequence for each enumerator. - /// Sequence resulting from applying the selector function to the shared view over the source - /// sequence. - /// or is . - public static IEnumerable Share(this IEnumerable source, Func, IEnumerable> selector) - { - Guard.IsNotNull(source); - Guard.IsNotNull(selector); - - return Core(source, selector); - - static IEnumerable Core(IEnumerable source, Func, IEnumerable> selector) - { - using var buffer = source.Share(); - foreach (var i in selector(buffer)) - yield return i; - } - } - private sealed class SharedBuffer : IBuffer { private readonly object _lock = new(); diff --git a/Tests/SuperLinq.Async.Test/ShareTest.cs b/Tests/SuperLinq.Async.Test/ShareTest.cs index c035e140f..235798db0 100644 --- a/Tests/SuperLinq.Async.Test/ShareTest.cs +++ b/Tests/SuperLinq.Async.Test/ShareTest.cs @@ -259,19 +259,4 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - - [Fact] - public void ShareLambdaIsLazy() - { - _ = new AsyncBreakingSequence().Share(BreakingFunc.Of, IAsyncEnumerable>()); - } - - [Fact] - public async Task ShareLambdaSimple() - { - await using var seq = Enumerable.Range(0, 10).AsTestingSequence(); - - var result = seq.Share(xs => xs.Zip(xs, (l, r) => l + r).Take(4)); - await result.AssertSequenceEqual(1, 5, 9, 13); - } } diff --git a/Tests/SuperLinq.Test/ShareTest.cs b/Tests/SuperLinq.Test/ShareTest.cs index 4701f9e2e..33566ab7c 100644 --- a/Tests/SuperLinq.Test/ShareTest.cs +++ b/Tests/SuperLinq.Test/ShareTest.cs @@ -259,19 +259,4 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - - [Fact] - public void ShareLambdaIsLazy() - { - _ = new BreakingSequence().Share(BreakingFunc.Of, IEnumerable>()); - } - - [Fact] - public void ShareLambdaSimple() - { - using var seq = Enumerable.Range(0, 10).AsTestingSequence(); - - var result = seq.Share(xs => xs.Zip(xs, (l, r) => l + r).Take(4)); - result.AssertSequenceEqual(1, 5, 9, 13); - } }