:whatever:
:)
:D
:lenny:
:shrug:
foreach (var i in EndlessCounter().Take(5)) { Log(i); // 0, 1, 2, 3, 4 is logged }
public IEnumerable<int> EndlessCounter() { var i = 0; while (true) { yield i++; } }
yield return
foreach (var x in xs) yield return x;
function* prompt() { console.log('What is your name?'); const name = yield; console.log(`Hello ${name}!`); } const iter = prompt(); // iter is an iterator object. // What is your name? printed iter.next('Madara'); // Hello Madara! printed
.Where()
public IEnumerable<T> filter<T>(IEnumerable<T> xs, Predicate<T> p) { foreach (var x in xs) { if (p(x)) { yield return x; } } }
foreach