Title: I added this code as a comment to a thread that was almost all the way off the front page by the time I got to it.  It was a response to some &#x27;functional folks&#x27; criticizing the verbosity of c#.  While you can certainly do c# the java way, you can also do it in a <i>near</i> functional way.<p>I decided to post the code as a full submission because I think c# often gets dismissed as Java copy-cat, which hasn&#x27;t been true in a decade.<p>The code (non-destructive, no side effects) calculates square roots :<p><pre><code>    public static void Main()
    {
        const int n = 21;

        Observable.Generate&lt;double,double&gt;(1, x=&gt;true, x=&gt; 0.5 * (x + (n&#x2F;x)), x=&gt;x )
        .Scan(new {prv = 0d, cur = 0d}, (prev, curr) =&gt; new {prv = prev.cur, cur = curr})
        .FirstAsync(_ =&gt; Math.Abs(_.cur - _.prv) &lt; 1E-10)
        .Select(_ =&gt; _.cur)
        .Subscribe(Console.WriteLine);

        &#x2F;&#x2F; this is just to compare values, so is not part of the solution
        Console.WriteLine(Math.Sqrt(n)); 
        Console.ReadLine();
    }
</code></pre>
Read the more OO c# implementation that inspired me here:
https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7044497<p>Read the Haskell code that inspired both here:
https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7043943
Upvote: