diff --git a/X10D/src/ByteExtensions.cs b/X10D/src/ByteExtensions.cs index 02302cf..3412cfc 100644 --- a/X10D/src/ByteExtensions.cs +++ b/X10D/src/ByteExtensions.cs @@ -20,28 +20,6 @@ return BitConverter.ToString(bytes.ToArray()); } - /// - /// Splits into chunks of size . - /// - /// The collection to split. - /// The maximum length of the nested collection. - /// Returns an of of - /// values. - public static IEnumerable> Chunkify(this IEnumerable bytes, int chunkSize) - { - IEnumerable enumerable = bytes as byte[] ?? bytes.ToArray(); - long count = enumerable.LongCount(); - List> chunks = new List>(); - chunkSize = chunkSize.Clamp(1, enumerable.Count()); - - for (int i = 0; i < (int) (count / chunkSize); i++) - { - chunks.Add(enumerable.Skip(i * chunkSize).Take(chunkSize)); - } - - return chunks.ToArray(); - } - /// /// Converts the [] to an . /// diff --git a/X10D/src/EnumerableExtensions.cs b/X10D/src/EnumerableExtensions.cs new file mode 100644 index 0000000..d82b0ff --- /dev/null +++ b/X10D/src/EnumerableExtensions.cs @@ -0,0 +1,31 @@ +namespace X10D +{ + using System.Collections.Generic; + using System.Linq; + + /// + /// Extension methods for . + /// + public static class EnumerableExtensions + { + /// + /// Splits into chunks of size . + /// + /// Any type. + /// The collection to split. + /// The maximum length of the nested collection. + /// Returns an of of + /// values. + public static IEnumerable> Split(this IEnumerable value, int chunkSize) + { + T[] enumerable = value.ToArray(); + var count = enumerable.LongCount(); + chunkSize = chunkSize.Clamp(1, enumerable.Length); + + for (var i = 0; i < (int)(count / chunkSize); i++) + { + yield return enumerable.Skip(i * chunkSize).Take(chunkSize); + } + } + } +}