public static int CopyTo <T>(this IIterable <T> c, T[] array, int arrayIndex) { bool ended = false; var it = c.GetIterator(); for (T current = it(ref ended); !ended; current = it(ref ended)) { array[arrayIndex++] = current; } return(arrayIndex); }
public static IEnumerable <KeyValuePair <Tuple <TK1, TK2>, Tuple <TV1, TV2> > > Join <TK1, TV1, TK2, TV2>( this IIterable <TK1, TV1> e1, IIterable <TK2, TV2> e2, Func <TK1, TK2, int> compare) { using var it1 = e1.GetIterator(); using var it2 = e2.GetIterator(); if (!it1.MoveNext() || !it2.MoveNext()) { yield break; } KeyValuePair <TK1, TV1> kv1 = it1.Current; KeyValuePair <TK2, TV2> kv2 = it2.Current; while (true) { int comparison = compare(kv1.Key, kv2.Key); if (comparison == 0) { // kv1 == kv2 yield return(new KeyValuePair <Tuple <TK1, TK2>, Tuple <TV1, TV2> >( Tuple.Create(kv1.Key, kv2.Key), Tuple.Create(kv1.Value, kv2.Value))); if (!it2.MoveNext()) { yield break; } kv2 = it2.Current; } else if (comparison < 0) { // kv1 < kv2 if (!it1.MoveNext()) { yield break; } kv1 = it1.Current; } else if (comparison > 0) { // kv1 > kv2 if (!it2.MoveNext()) { yield break; } kv2 = it2.Current; } } }
public void PushLast(IIterable <T> items) { for (Iterator <T> it = items.GetIterator();;) { bool ended = false; T item = it(ref ended); if (ended) { break; } PushLast(item); } }
private static IEnumerable <T> AsEnumerableCore <T>(IIterable <T> list) { bool ended = false; for (var it = list.GetIterator();;) { T item = it(ref ended); if (ended) { yield break; } yield return(item); } }
/// <summary>Determines whether the source contains a specific value.</summary> /// <returns>true if an element that equals 'item' was found, false otherwise.</returns> /// <remarks> /// Contains() was originally a member of the ISource(T) interface, just in /// case the source had some kind of fast lookup logic. However, this is /// not allowed in C# 4 when T is marked as "out" (covariant), so Contains() /// must be an extension method. /// </remarks> public static bool Contains <T>(this IIterable <T> list, T item) { EqualityComparer <T> comparer = EqualityComparer <T> .Default; bool ended = false; var it = list.GetIterator(); for (T current = it(ref ended); !ended; current = it(ref ended)) { if (comparer.Equals(item, current)) { return(true); } } return(false); }
public override Iterator <TOut> GetIterator() { var it = s.GetIterator(); return(Iterator.UpCast <T, TOut>(it)); }
// Implement the non-generic IEnumerable interface. public IEnumerator GetEnumerator() { return(new EnumeratorAdapter <T>(e.GetIterator())); }