sdk/dotnet/src/Microsoft.Datasync.Client.SQLiteStore/Utils/ExtensionMethods.cs
/// <summary>
/// Splits the given sequence into sequences of the given length.
/// </summary>
Splits the given sequence into sequences of the given length.
Splits the given sequence into sequences of the given length .
internal static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> source, int maxLength)
        {
            Arguments.IsNotNull(source, nameof(source));
            Arguments.IsPositiveInteger(maxLength, nameof(maxLength));
            var enumerator = source.GetEnumerator();
            var batch = new List<T>(maxLength);
            while (enumerator.MoveNext())
            {
                batch.Add(enumerator.Current);
                if (batch.Count == maxLength)
                {
                    yield return batch;
                    batch = new List<T>(maxLength);
                }
            }
            if (batch.Count > 0)
            {
                yield return batch;
            }
        }
internal static IEnumerable < IEnumerable < T > > Split < T > ( this IEnumerable < T > source , int maxLength ) { Arguments . IsNotNull ( source , nameof ( source ) ) ; Arguments . IsPositiveInteger ( maxLength , nameof ( maxLength ) ) ; var enumerator = source . GetEnumerator ( ) ; var batch = new List < T > ( maxLength ) ; while ( enumerator . MoveNext ( ) ) { batch . Add ( enumerator . Current ) ; if ( batch . Count == maxLength ) { yield return batch ; batch = new List < T > ( maxLength ) ; } } if ( batch . Count > 0 ) { yield return batch ; } }
Splits the given sequence into sequences of the given length.
Splits the given sequence into sequences of the given length .
IEnumerable<T>
this
maxLength
int