// this is wrong
public IEnumerable<T> MyFunction(Func<T, T> function, int iteration)
{
yield return Enumerable.Repeat<T>(function.Invoke(), iteration);
}
you return whole IEnumerable collection returned by Repeat(...) in a single yield (pointless).
Another problem of your method is return type. If you want to return your Func objects you have to replace return type of your method from IEnumerable<T>
to Func<T,T>
.
Purpose of Enumerable.Repeat<T>(...)
method is to create a collection with N instances of given object and return whole collection.
If you want to return objects in yields you have to return these objects one by one.
I think you need something like this:
(for better understanding I'm not using LINQ and lambda expressions)
public Func<T,T> MyFunction(Func<T, T> function, int iteration)
{
// create a collection with `N = interation` items
IEnumerable<Func<T,T>> items = Enumerable.Repeat<T>(function.Invoke(), iteration);
// return items
foreach(Func<T,T> item in items)
{
yield return item;
}
}