I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.TakeWhile((x, i) => i == 0 ? true : !pred(x));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>SplitBeforeIf4<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
intIGrouping<bool, tmpCountT> group = 0;
null;
while (tmpCount >= 0)
{
tmpCount = -1;
var (group = input.Skip(count).TakeWhile((x, i) => i == 0 ? true : !pred(x)).GroupBy(x => true).FirstOrDefault();
if (group) != null)
{
yield return group.Select(x => x);
tmpCountcount =+= group.Count();
count += tmpCount;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.TakeWhile((x, i) => i == 0 ? true : !pred(x));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
var group = input.Skip(count).TakeWhile((x, i) => i == 0 ? true : !pred(x)).GroupBy(x => true).FirstOrDefault();
if (group != null)
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.TakeWhile((x, i) => i == 0 ? true : !pred(x));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf4<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
IGrouping<bool, T> group = null;
while ((group = input.Skip(count).TakeWhile((x, i) => i == 0 ? true : !pred(x)).GroupBy(x => true).FirstOrDefault()) != null)
{
yield return group.Select(x => x);
count += group.Count();
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.Take(1).Concat(input.Skip(1).TakeWhile((x, i) => i == 0 ? true : !pred(x)));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
foreach (var group in= input.Skip(count).TakeWhile((x, i) => i == 0? true : !pred(x)).GroupBy(x => true).FirstOrDefault();
if (group != null)
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
if (tmpCount == 0)
tmpCount = -1;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.Take(1).Concat(input.Skip(1).TakeWhile(x => !pred(x)));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
foreach (var group in input.Skip(count).TakeWhile((x, i) => i == 0? true : !pred(x)).GroupBy(x => true))
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
if (tmpCount == 0)
tmpCount = -1;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.TakeWhile((x, i) => i == 0 ? true : !pred(x));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
var group = input.Skip(count).TakeWhile((x, i) => i == 0? true : !pred(x)).GroupBy(x => true).FirstOrDefault();
if (group != null)
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.Take(1).Concat(input.Skip(1).TakeWhile(x => !pred(x)));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
foreach (var group in input.Skip(count).TakeWhile((x, i) => i == 0? true : !pred(x)).GroupBy(x => true))
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
if (tmpCount == 0)
tmpCount = -1;
}
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.Take(1).Concat(input.Skip(1).TakeWhile(x => !pred(x)));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
I can't help you with your questions, but below you'll find another implementation which avoids instatiation of new lists. The penalty is though the lst.Count(), but if the frequence of elements satisfying the predicate is high it may be ok?
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
var lst = input.Take(1).Concat(input.Skip(1).TakeWhile(x => !pred(x)));
var count = lst.Count();
if (count > 0)
{
yield return lst;
foreach (var l in input.Skip(count).SplitBeforeIf2(pred))
yield return l;
}
}
As the above solution has a rather poor performance for large datasets, I went on and found the solution below which seems to be more effecient:
public static IEnumerable<IEnumerable<T>> SplitBeforeIf2<T>(this IEnumerable<T> input, Func<T, bool> pred)
{
int count = 0;
int tmpCount = 0;
while (tmpCount >= 0)
{
tmpCount = -1;
foreach (var group in input.Skip(count).TakeWhile((x, i) => i == 0? true : !pred(x)).GroupBy(x => true))
{
yield return group.Select(x => x);
tmpCount = group.Count();
count += tmpCount;
if (tmpCount == 0)
tmpCount = -1;
}
}
}