1
0
Fork 0
mirror of https://github.com/wagesj45/mdfinder.git synced 2025-09-09 03:20:38 -05:00

Beginning Work

This is early stage development. Still getting the main components together and figureing out how the flow should work.
This commit is contained in:
Jordan Wages 2019-02-14 02:18:46 -06:00
commit f5b2f9e0f6
19 changed files with 1317 additions and 29 deletions

31
mdfinder/Extensions.cs Normal file
View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mdfinder
{
public static class Extensions
{
/// <summary> Enumerates <paramref name="items"/> into bins of size <paramref name="binSize"/>. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="items"> The items to act on. </param>
/// <param name="binSize"> Size of the bin. </param>
/// <returns>
/// An enumerator that allows foreach to be used to process bin in this collection.
/// </returns>
/// <remarks> Thanks to @juharr at Stack Overflow. https://stackoverflow.com/a/32970228/1210377 </remarks>
public static IEnumerable<IEnumerable<T>> Bin<T>(this IEnumerable<T> items, int binSize)
{
if(binSize <= 0)
{
throw new ArgumentOutOfRangeException("binSize", Localization.Localization.BinSizeOutOfRangeExceptionMessage);
}
return items.Select((x, i) => new { x, i })
.GroupBy(a => a.i / binSize)
.Select(grp => grp.Select(a => a.x));
}
}
}