Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Invalid Share overload #556

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T, TResult>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Func<System.Collections.Generic.IAsyncEnumerable<T>!, System.Collections.Generic.IAsyncEnumerable<T>!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<TResult>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable<T>! True, System.Collections.Generic.IAsyncEnumerable<T>! False)>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T, TResult>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Func<System.Collections.Generic.IAsyncEnumerable<T>!, System.Collections.Generic.IAsyncEnumerable<T>!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<TResult>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable<T>! True, System.Collections.Generic.IAsyncEnumerable<T>! False)>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T, TResult>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Func<System.Collections.Generic.IAsyncEnumerable<T>!, System.Collections.Generic.IAsyncEnumerable<T>!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<TResult>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable<T>! True, System.Collections.Generic.IAsyncEnumerable<T>! False)>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T, TResult>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Func<System.Collections.Generic.IAsyncEnumerable<T>!, System.Collections.Generic.IAsyncEnumerable<T>!, TResult>! resultSelector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<TResult>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Partition<T>(this System.Collections.Generic.IAsyncEnumerable<T>! source, System.Func<T, bool>! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<(System.Collections.Generic.IAsyncEnumerable<T>! True, System.Collections.Generic.IAsyncEnumerable<T>! False)>
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
*REMOVED*static SuperLinq.Async.AsyncSuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, System.Func<System.Collections.Generic.IAsyncEnumerable<TSource>!, System.Collections.Generic.IAsyncEnumerable<TResult>!>! selector) -> System.Collections.Generic.IAsyncEnumerable<TResult>!
32 changes: 0 additions & 32 deletions Source/SuperLinq.Async/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,6 @@ public static IAsyncBuffer<TSource> Share<TSource>(this IAsyncEnumerable<TSource
return new SharedBuffer<TSource>(source);
}

/// <summary>
/// Shares the source sequence within a selector function where each enumerator can fetch the next element from the
/// source sequence.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <typeparam name="TResult">Result sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="selector">Selector function with shared access to the source sequence for each enumerator.</param>
/// <returns>Sequence resulting from applying the selector function to the shared view over the source
/// sequence.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is <see
/// langword="null"/>.</exception>
public static IAsyncEnumerable<TResult> Share<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
Func<IAsyncEnumerable<TSource>, IAsyncEnumerable<TResult>> selector)
{
Guard.IsNotNull(source);
Guard.IsNotNull(selector);

return Core(source, selector);

static async IAsyncEnumerable<TResult> Core(
IAsyncEnumerable<TSource> source,
Func<IAsyncEnumerable<TSource>, IAsyncEnumerable<TResult>> 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<T> : IAsyncBuffer<T>
{
private readonly SemaphoreSlim _lock = new(initialCount: 1);
Expand Down
1 change: 1 addition & 0 deletions Source/SuperLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, System.Func<TKey, TAccumulate>! seedSelector, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, TAccumulate seed, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
*REMOVED*static SuperLinq.SuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
*REMOVED*static SuperLinq.SuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
1 change: 1 addition & 0 deletions Source/SuperLinq/PublicAPI/net7.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, System.Func<TKey, TAccumulate>! seedSelector, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, TAccumulate seed, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
*REMOVED*static SuperLinq.SuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
*REMOVED*static SuperLinq.SuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
1 change: 1 addition & 0 deletions Source/SuperLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, System.Func<TKey, TAccumulate>! seedSelector, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, TAccumulate seed, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
*REMOVED*static SuperLinq.SuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
*REMOVED*static SuperLinq.SuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, System.Func<TKey, TAccumulate>! seedSelector, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
static SuperLinq.SuperEnumerable.AggregateBy<TSource, TKey, TAccumulate>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<TSource, TKey>! keySelector, TAccumulate seed, System.Func<TAccumulate, TSource, TAccumulate>! func, System.Collections.Generic.IEqualityComparer<TKey>? comparer = null) -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TAccumulate>>!
*REMOVED*static SuperLinq.SuperEnumerable.Publish<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
*REMOVED*static SuperLinq.SuperEnumerable.Share<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource>! source, System.Func<System.Collections.Generic.IEnumerable<TSource>!, System.Collections.Generic.IEnumerable<TResult>!>! selector) -> System.Collections.Generic.IEnumerable<TResult>!
27 changes: 0 additions & 27 deletions Source/SuperLinq/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,6 @@ public static IBuffer<TSource> Share<TSource>(this IEnumerable<TSource> source)
return new SharedBuffer<TSource>(source);
}

/// <summary>
/// Shares the source sequence within a selector function where each enumerator can fetch the next element from the
/// source sequence.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <typeparam name="TResult">Result sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="selector">Selector function with shared access to the source sequence for each enumerator.</param>
/// <returns>Sequence resulting from applying the selector function to the shared view over the source
/// sequence.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is <see
/// langword="null"/>.</exception>
public static IEnumerable<TResult> Share<TSource, TResult>(this IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
{
Guard.IsNotNull(source);
Guard.IsNotNull(selector);

return Core(source, selector);

static IEnumerable<TResult> Core(IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumerable<TResult>> selector)
{
using var buffer = source.Share();
foreach (var i in selector(buffer))
yield return i;
}
}

private sealed class SharedBuffer<T> : IBuffer<T>
{
private readonly object _lock = new();
Expand Down
15 changes: 0 additions & 15 deletions Tests/SuperLinq.Async.Test/ShareTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,4 @@ public IEnumerator<int> GetEnumerator()

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

[Fact]
public void ShareLambdaIsLazy()
{
_ = new AsyncBreakingSequence<int>().Share(BreakingFunc.Of<IAsyncEnumerable<int>, IAsyncEnumerable<string>>());
}

[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);
}
}
15 changes: 0 additions & 15 deletions Tests/SuperLinq.Test/ShareTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,4 @@ public IEnumerator<int> GetEnumerator()

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

[Fact]
public void ShareLambdaIsLazy()
{
_ = new BreakingSequence<int>().Share(BreakingFunc.Of<IEnumerable<int>, IEnumerable<string>>());
}

[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);
}
}