currently I am still doing this question :
Make a general purpose infinite sequence initialisation function that creates infinite lazy sequences. It will take as parameter a function to compute the next value from the current value. In other words, it should be a “factory” for functions like naturalNumbers. Thus, if we call our function initSequence, then initSequence(n=>n+1) will return a function equivalent to naturalNumbers.
this template is given
interface LazySequence<T> {
value: T;
next(): LazySequence<T>;
}
// Implement the function:
function initSequence<T>(transform: (value: T) => T): (initialValue: T) => LazySequence<T>
{
// Your code here
}
So far, this is my code in TypeScript
interface LazySequence<T> {
value: T;
next(): LazySequence<T>;
}
// Implement the function:
function initSequence<T>(transform: (value: T) => T): (initialValue: T) => LazySequence<T>
{
// Your code here ...
return () => initSequence(v=>v+1) => LazySequence;
}
and it seemed like the code doesn't work accordingly. can anybody help? then can anybody make a clear explanation regarding lazy evaluation, lazy iteration and another lazy things? thanks a lot