public void SourceWithSingleValue_ReturnsJustCurrent() { var iterator = EnumerableEx.Return(0).ToPrevNextIterator(); var standard = new[] { new PrevNextValue <int>(Optional <int> .None, 0, Optional <int> .None) }; CollectionAssert.AreEqual(iterator, standard); }
static IEnumerable <IEnumerable <T> > SplitWithBordersIterator <T>(IEnumerable <T> source, Relation <T, T, T> relation) { List <T> acc; using (var enumerator = source.GetEnumerator()) { if (!enumerator.MoveNext()) { yield break; } T first = enumerator.Current; if (!enumerator.MoveNext()) { yield return(EnumerableEx.Return(first)); yield break; } T second = enumerator.Current; acc = new List <T> { first, second }; while (enumerator.MoveNext()) { T item = enumerator.Current; if (relation(first, second, item)) { acc.Add(item); } else { yield return(acc); acc = new List <T> { second, item }; } first = second; second = item; } } if (acc.Count > 0) { yield return(acc); } }
public void Except_OnlyTargetItem_ReturnsEmpty() { var items = EnumerableEx.Return(0); CollectionAssert.IsEmpty(items.Except(0)); }
public static IEnumerable <T> Generate <T>(T state, Predicate <T> condition, Func <T, T> iterate) { return(EnumerableEx.Generate(state, x => condition(x), iterate, Functions.Identity <T>())); }