We have iterate function in haskell Prelude
iterate :: (a -> a) -> a -> [a]
iterate f x == [x, f x, f (f x), ...]
What is the equivalent in C#?
We have iterate function in haskell Prelude
iterate :: (a -> a) -> a -> [a]
iterate f x == [x, f x, f (f x), ...]
What is the equivalent in C#?
There isn't one but you can write your own:
public static IEnumerable<T> Iterate<T>(T seed, Func<T, T> step)
{
while(true)
{
yield return seed;
seed = step(seed);
}
}