title: What is an anamorphism, and how does one look like in C#?
body: <p>I am trying to wrap my head around the concept of anamorphism.</p>
  
  <blockquote>
    <p>In functional programming, an anamorphism is a generalization of the concept of unfolds on lists. Formally, anamorphisms are generic functions that can corecursively construct a result of a certain type and which is parameterized by functions that determine the next single step of the construction.</p>
  </blockquote>
  
  <hr>
  
  <p>Its dual, catamorphism, is nicely described in this post: <a href="https://stackoverflow.com/questions/196294/what-is-a-catamorphism-and-can-it-be-implemented-in-c-sharp-3-0">What is a catamorphism and can it be implemented in C# 3.0?</a>.</p>
  
  <p>A nice example of catamorphic behavior in C# is the LINQ's <a href="https://msdn.microsoft.com/en-us/library/vstudio/bb548651(v=vs.100).aspx" rel="nofollow noreferrer">Aggregate</a> method.</p>
  
  <hr>
  
  <p>What would an anamorphic equivalent be? Is it correct to think of a pseudo-random number generator <a href="https://msdn.microsoft.com/en-us/library/system.random(v=vs.110).aspx" rel="nofollow noreferrer">Random</a> as an anamorphic construct or should the process of unfolding always include an accumulator function like the one below (code snippet taken from <a href="http://www.introtorx.com/Content/v1.0.10621.0/04_CreatingObservableSequences.html#ObservableGenerate" rel="nofollow noreferrer">Intro to Rx</a>)?</p>
  
  <pre><code>IEnumerable&lt;T&gt; Unfold&lt;T&gt;(T seed, Func&lt;T, T&gt; accumulator)
  {
      var nextValue = seed;
      while (true)
      {
          yield return nextValue;
          nextValue = accumulator(nextValue);
      }
  }
  </code></pre>