Jump to content

Generator/Exponential: Difference between revisions

Line 696:
public static Func<int> FilterAsClosure(Func<int> squaresGenerator, Func<int> cubesGenerator)
{
int valuesquareValue;
int filtercubeValue = cubesGenerator();
return () =>
{
while (true)
{
valuesquareValue = squaresGenerator();
while (valuesquareValue > filtercubeValue)
filtercubeValue = cubesGenerator();
if (valuesquareValue < filtercubeValue)
return valuesquareValue;
}
};
Line 742:
public static IEnumerable<int> FilterAsList(IEnumerator<int> squaresGenerator, IEnumerator<int> cubesGenerator)
{
int valuesquareValue;
int filtercubeValue = cubesGenerator.Current;
while (true)
{
valuesquareValue = squaresGenerator.Current;
while (valuesquareValue > filtercubeValue)
{
cubesGenerator.MoveNext();
filtercubeValue = cubesGenerator.Current;
}
if (valuesquareValue < filtercubeValue)
yield return valuesquareValue;
squaresGenerator.MoveNext();
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.