Hacker News new | ask | show | jobs
by shaftway 3695 days ago
I liked the article. Maybe a bit about how the LinQ methods are (or could be) implemented under the hood to show how easy this can actually be?

I've always like the good old fibonacci sequence for this too, because it shows off some simple logic that we all know, but it touches on some non-intuitive aspects (like yields being anywhere, and infinitely long IEnumerables).

    public IEnumerable<int> Fib() {
      yield return 1;
      yield return 1;

      int a = 1, b = 1;
      while (true) {
        b = a + b;
        a = b - a;
        yield return b;
      }
    }
Then the 500th fibonachi number is:

    Fib().Skip(499).Next()