src/Kingdom.OrTools.Sat.Parameters.Tests/Extensions/CollectionExtensionMethods.cs
// ReSharper disable PossibleMultipleEnumeration
/// <summary>
/// Permutations are overkill. This approach is quite perfectly adequate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="values"></param>
/// <param name="k"></param>
/// <param name="slice"></param>
/// <param name="remaining"></param>
/// <returns></returns>
Permutations are overkill. This approach is quite perfectly adequate.
Permutations are overkill . This approach is quite perfectly adequate .
public static bool TrySliceOverCollection<T>(this IEnumerable<T> values, int k, out IEnumerable<T> slice, out IEnumerable<T> remaining)
        {
            var x = values.Count() / k;
            slice = (x > 0 ? values.Where((y, i) => i % x == 0) : values).ToArray();
            remaining = (x > 0 ? values.Where((y, i) => i % x != 0) : Array.Empty<T>()).ToArray();
            return slice.Any();
        }
public static bool TrySliceOverCollection < T > ( this IEnumerable < T > values , int k , out IEnumerable < T > slice , out IEnumerable < T > remaining ) { var x = values . Count ( ) / k ; slice = ( x > 0 ? values . Where ( ( y , i ) => i % x == 0 ) : values ) . ToArray ( ) ; remaining = ( x > 0 ? values . Where ( ( y , i ) => i % x != 0 ) : Array . Empty < T > ( ) ) . ToArray ( ) ; return slice . Any ( ) ; }
Permutations are overkill.
Permutations are overkill .
// Default to Values and Empty Array when there are effectively Fewer Remaining.
None
IEnumerable<T>
out
k
int
None
values
None
slice
None
remaining
None
typeparam
None