Skip to content

Commit

Permalink
Update operators to use IReadOnlyList<> (#599)
Browse files Browse the repository at this point in the history
* Update `Split` to use `IReadOnlyList<>` as return type
* Update `Segment` to use `IReadOnlyList<>`
* Update `GroupAdjacent` to use `IReadOnlyList<>`
  • Loading branch information
viceroypenguin authored Dec 9, 2023
1 parent ac62852 commit c7e6913
Show file tree
Hide file tree
Showing 16 changed files with 445 additions and 149 deletions.
4 changes: 2 additions & 2 deletions Source/SuperLinq.Async/GroupAdjacent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static IAsyncEnumerable<IGrouping<TKey, TElement>> GroupAdjacent<TSource,
public static IAsyncEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector)
Func<TKey, IReadOnlyList<TSource>, TResult> resultSelector)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
Expand Down Expand Up @@ -241,7 +241,7 @@ public static IAsyncEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
public static IAsyncEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
this IAsyncEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector,
Func<TKey, IReadOnlyList<TSource>, TResult> resultSelector,
IEqualityComparer<TKey>? comparer)
{
ArgumentNullException.ThrowIfNull(source);
Expand Down
46 changes: 43 additions & 3 deletions Source/SuperLinq.Async/PublicAPI/net6.0/PublicAPI.Unshipped.txt

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions Source/SuperLinq.Async/PublicAPI/net7.0/PublicAPI.Unshipped.txt

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions Source/SuperLinq.Async/PublicAPI/net8.0/PublicAPI.Unshipped.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Source/SuperLinq.Async/Segment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static partial class AsyncSuperEnumerable
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, bool> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, bool> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);
Expand All @@ -32,7 +32,7 @@ public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, ValueTask<bool>> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, ValueTask<bool>> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);
Expand All @@ -51,7 +51,7 @@ public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, int, bool> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, int, bool> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);
Expand All @@ -70,7 +70,7 @@ public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, int, ValueTask<bool>> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, int, ValueTask<bool>> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);
Expand All @@ -89,7 +89,7 @@ public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, T, int, bool> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, T, int, bool> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);
Expand All @@ -108,14 +108,14 @@ public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<
/// Thrown if either <paramref name="source"/> or <paramref name="newSegmentPredicate"/> are <see langword="null"/>.
/// </exception>

public static IAsyncEnumerable<IEnumerable<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, T, int, ValueTask<bool>> newSegmentPredicate)
public static IAsyncEnumerable<IReadOnlyList<T>> Segment<T>(this IAsyncEnumerable<T> source, Func<T, T, int, ValueTask<bool>> newSegmentPredicate)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(newSegmentPredicate);

return Core(source, newSegmentPredicate);

static async IAsyncEnumerable<IEnumerable<T>> Core(IAsyncEnumerable<T> source, Func<T, T, int, ValueTask<bool>> newSegmentPredicate, [EnumeratorCancellation] CancellationToken cancellationToken = default)
static async IAsyncEnumerable<IReadOnlyList<T>> Core(IAsyncEnumerable<T> source, Func<T, T, int, ValueTask<bool>> newSegmentPredicate, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken);

Expand Down
26 changes: 13 additions & 13 deletions Source/SuperLinq.Async/Split.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static partial class AsyncSuperEnumerable
/// <param name="separator">Separator element.</param>
/// <returns>A sequence of splits of elements.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
TSource separator)
{
Expand All @@ -28,7 +28,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
/// <returns>A sequence of splits of elements.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than 1.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
TSource separator, int count)
{
Expand All @@ -53,7 +53,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
TSource separator,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
return Split(source, separator, int.MaxValue, resultSelector);
}
Expand All @@ -78,7 +78,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
TSource separator, int count,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
return Split(source, separator, null, count, resultSelector);
}
Expand All @@ -94,7 +94,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
/// element equality.</param>
/// <returns>A sequence of splits of elements.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
TSource separator, IEqualityComparer<TSource>? comparer)
{
Expand All @@ -115,7 +115,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
/// <returns>A sequence of splits of elements.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than 1.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
TSource separator, IEqualityComparer<TSource>? comparer, int count)
{
Expand Down Expand Up @@ -143,7 +143,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
TSource separator, IEqualityComparer<TSource> comparer,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
return Split(source, separator, comparer, int.MaxValue, resultSelector);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
TSource separator, IEqualityComparer<TSource>? comparer, int count,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
Expand All @@ -192,7 +192,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
/// <returns>A sequence of splits of elements.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="separatorFunc"/> is <see langword="null"/>.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
Func<TSource, bool> separatorFunc)
{
Expand All @@ -212,7 +212,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="separatorFunc"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than 1.</exception>
public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<IReadOnlyList<TSource>> Split<TSource>(
this IAsyncEnumerable<TSource> source,
Func<TSource, bool> separatorFunc, int count)
{
Expand All @@ -239,7 +239,7 @@ public static IAsyncEnumerable<IEnumerable<TSource>> Split<TSource>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
Func<TSource, bool> separatorFunc,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
return Split(source, separatorFunc, int.MaxValue, resultSelector);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
this IAsyncEnumerable<TSource> source,
Func<TSource, bool> separatorFunc, int count,
Func<IEnumerable<TSource>, TResult> resultSelector)
Func<IReadOnlyList<TSource>, TResult> resultSelector)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(separatorFunc);
Expand All @@ -279,7 +279,7 @@ public static IAsyncEnumerable<TResult> Split<TSource, TResult>(
static async IAsyncEnumerable<TResult> Core(
IAsyncEnumerable<TSource> source,
Func<TSource, bool> separatorFunc, int count,
Func<IEnumerable<TSource>, TResult> resultSelector,
Func<IReadOnlyList<TSource>, TResult> resultSelector,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var items = new List<TSource>();
Expand Down
4 changes: 2 additions & 2 deletions Source/SuperLinq/GroupAdjacent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static IEnumerable<IGrouping<TKey, TElement>> GroupAdjacent<TSource, TKey
public static IEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector)
Func<TKey, IReadOnlyList<TSource>, TResult> resultSelector)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(keySelector);
Expand Down Expand Up @@ -276,7 +276,7 @@ public static IEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
public static IEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector,
Func<TKey, IReadOnlyList<TSource>, TResult> resultSelector,
IEqualityComparer<TKey>? comparer)
{
ArgumentNullException.ThrowIfNull(source);
Expand Down
Loading

0 comments on commit c7e6913

Please sign in to comment.