Westmoor.DowntimePlanner/Extensions/EnumerableExtensions.cs
/// <summary>
/// Race a source enumerable against a set candidates. The first one to yield
/// a value will win the race and get to yield all of its values. Other
/// candidates are ignored. Candidates are raced in order that they were provided.
/// </summary>
/// <param name="source"></param>
/// <param name="candidates"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
Race a source enumerable against a set candidates. The first one to yield
a value will win the race and get to yield all of its values. Other
candidates are ignored. Candidates are raced in order that they were provided.
Race a source enumerable against a set candidates . The first one to yield a value will win the race and get to yield all of its values . Other candidates are ignored . Candidates are raced in order that they were provided .
public static IEnumerable<T> Race<T>(this IEnumerable<T> source, params IEnumerable<T>[] candidates)
        {
            var didYield = false;
            foreach (var candidate in candidates.Prepend(source))
            {
                foreach (var value in candidate)
                {
                    didYield = true;
                    yield return value;
                }
                if (didYield)
                {
                    yield break;
                }
            }
        }
public static IEnumerable < T > Race < T > ( this IEnumerable < T > source , params IEnumerable < T > [ ] candidates ) { var didYield = false ; foreach ( var candidate in candidates . Prepend ( source ) ) { foreach ( var value in candidate ) { didYield = true ; yield return value ; } if ( didYield ) { yield break ; } } }
Race a source enumerable against a set candidates.
Race a source enumerable against a set candidates .
None
IEnumerable<T>
this
source
None
candidates
None
typeparam
None