diff --git a/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 73b491b5..bdc6e241 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 73b491b5..bdc6e241 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 73b491b5..bdc6e241 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 73b491b5..bdc6e241 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 d451a1e9..abe14e90 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 30eeb0bd..e72585ec 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 30eeb0bd..e72585ec 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 30eeb0bd..e72585ec 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 30eeb0bd..e72585ec 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 fcf21da5..ef02c4d2 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 c035e140..235798db 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 4701f9e2..33566ab7 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); - } }