Skip to content

Commit

Permalink
Improve Batch documentation [ci skip]
Browse files Browse the repository at this point in the history
Adds following remarks:

- The last bucket can be smaller than the given size.

- Memory could be exhausted if size is set to a very large value in
  the hope of forcing just a single bucket (morelinq#619).
  • Loading branch information
atifaziz committed Oct 29, 2019
1 parent bbc3a06 commit b9a5348
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions MoreLinq/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ static partial class MoreEnumerable
/// <param name="size">Size of buckets.</param>
/// <returns>A sequence of equally sized buckets containing elements of the source collection.</returns>
/// <remarks>
/// <para>
/// This operator uses deferred execution and streams its results
/// (buckets are streamed but their content buffered).
/// (buckets are streamed but their content buffered).</para>
/// <para>
/// When more than one bucket is streamed, all buckets except the last
/// is guaranteed to have <paramref name="size"/> elements. The last
/// bucket may be smaller depending on the remaining elements in the
/// <paramref name="source"/> sequence.</para>
/// <para>
/// Each bucket is pre-allocated to <paramref name="size"/> elements.
/// If <paramref name="size"/> is set to a very large value, e.g.
/// <see cref="int.MaxValue"/> to effectively disable batching by just
/// hoping for a single bucket, then it can lead to memory exhaustion
/// (<see cref="OutOfMemoryException"/>).
/// </para>
/// </remarks>

public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(this IEnumerable<TSource> source, int size)
Expand All @@ -48,10 +61,21 @@ public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(this IEnumerable<
/// <param name="size">Size of buckets.</param>
/// <param name="resultSelector">The projection to apply to each bucket.</param>
/// <returns>A sequence of projections on equally sized buckets containing elements of the source collection.</returns>
/// <remarks>
/// <para>
/// This operator uses deferred execution and streams its results
/// (buckets are streamed but their content buffered).
/// </remarks>
/// (buckets are streamed but their content buffered).</para>
/// <para>
/// <para>
/// When more than one bucket is streamed, all buckets except the last
/// is guaranteed to have <paramref name="size"/> elements. The last
/// bucket may be smaller depending on the remaining elements in the
/// <paramref name="source"/> sequence.</para>
/// Each bucket is pre-allocated to <paramref name="size"/> elements.
/// If <paramref name="size"/> is set to a very large value, e.g.
/// <see cref="int.MaxValue"/> to effectively disable batching by just
/// hoping for a single bucket, then it can lead to memory exhaustion
/// (<see cref="OutOfMemoryException"/>).
/// </para>

public static IEnumerable<TResult> Batch<TSource, TResult>(this IEnumerable<TSource> source, int size,
Func<IEnumerable<TSource>, TResult> resultSelector)
Expand Down

0 comments on commit b9a5348

Please sign in to comment.