Skip to content

EnumerableExtensions

Static extension class providing ChunkBy, a lazily evaluated helper that splits any IEnumerable<T> into successive fixed-size List<T> batches, used elsewhere in the codebase to batch work (e.g., bulk operations against external services) into manageable groups*.

Purpose

  • Splits a sequence into fixed-size batches without materializing the whole source sequence up front.

Context

  • Namespace: SAIF.Services.Utilities
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
ChunkBy<T> public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source, int chunkSize) Lazily yields successive List<T> chunks of at most chunkSize items from source, including a final partial chunk if the source length is not an exact multiple of chunkSize.

Behavioral notes

  • Throws ArgumentException immediately if chunkSize is zero or negative, before any enumeration of source begins.
  • Uses yield return, so chunks are produced incrementally as the caller enumerates the result rather than all at once.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Services/SAIF.Services/Utilities/EnumerableExtensions.cs