title: Functors when should I use them whats their intended use
body: <p>I Just can't seem to wrap my head around them.</p>
  
  <p>As I understand it's dynamically adding logic to a class. Are classes within the framework prepared for this?</p>
  
  <p>Why should I just extend the class and add the functionality to it in the extension. I would be globally accessible and afaik much easier to maintain.</p>
  
  <p>I've Read there are 4 functor types:</p>
  
  <p>Comparer<br>
  Closure<br>
  Predicate<br>
  Transformer  </p>
  
  <p>We should probably Handle each one of them.</p>
  
  <p>p.s. is there something like it in vb?</p>
  
  <p>So I can state I think that lambda expressions are functors. This clears up things for me a bit :) (hehe)</p>
  
  <ul>
  <li>Lambda expressions are functors?</li>
  <li>Anonymous functions are functors?</li>
  </ul>
  
  <p>But I asked this question because I ran into another type of fucntors namely these ones:</p>
  
  <pre><code>delegate void FunctorDelegate(int value);
  class Addition {
      FunctorDelegate _delegate;
  
      public Addition AddDelegate(FunctorDelegate deleg) {
          _delegate += deleg;
          return this;
      }
      public int AddAllElements(IList&lt; int&gt; list) {
          int runningTotal = 0;
          foreach( int value in list) {
              runningTotal += value;
              _delegate(value);
          }
          return runningTotal;
      }
  }
  </code></pre>
  
  <p>And then calling it with this:</p>
  
  <pre><code> int runningTotal = new Addition()
       .AddDelegate(new FunctorDelegate(
                       delegate(int value) {
                           if ((value % 2) == 1) {
                               runningOddTotal += value;
                           }
                       }))
      .AddDelegate(new FunctorDelegate(
                       delegate(int value) {
                           if ((value % 2) == 0) {
                               runningEvenTotal += value;
                           }
                       }))
      .AddAllElements(list);
  </code></pre>
  
  <p>So no fancy lambda style things.</p>
  
  <p>Now I have this example but it isn't at all clear why this is a "good" solution.</p>
  
  <p><strong>Are delegates (functors) used as lambda expressions or anonymous methods "in most cases" just there as a shortcut for the programmer? There are as far as I can see only a few cases where they're actually the prefered choice for a problem.</strong>  </p>