title: Streams Collectors.summingDouble dynamic function argument
body: <p>I have following code which works great if i hard-code pojo method <strong>Employee::getBaseSalary</strong></p>
  
  <pre><code>Map&lt;Date, Map&lt;String, Double&gt;&gt; $r = list
                                  .stream()
                                  .filter((p) -&gt; (StringUtils.equalsIgnoreCase(p.getActiveInd(), "Y")
                                                  &amp;&amp; CoreUtils.greaterThanOrEquals(p.getCreateDate(), paramDate) &amp;&amp; (null == p.getEmpDate())))
                                  .collect(Collectors.groupingBy(dateFn,
                                           Collectors.groupingBy(empCodeFn,
                                           Collectors.summingDouble(Employee::getBaseSalary))));
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Notice that i have java Function Objects used <em>dateFn</em> and <em>empCodeFn</em> in group by clause. I am trying to do the same for <em>summingDouble</em> as follows but it give compile errors??</p>
  
  <pre><code>    private Function&lt;Employee, Double&gt; getFunctionSpecialCalc() {
      switch (calculationType) {
          case BaseSalary:
              return Employee::getBaseSalary;
          case TotalSalary:
              return Employee::getTotalSalary;
          default:
              return Employee::getBaseSalary;
      }
  }
  </code></pre>
  
  <p>And i am intended to use it as follows:</p>
  
  <pre><code>Function&lt;Employee,Double&gt; calcFn = getFunctionSpecialCalc();
  ...
  ...    
  Collectors.summingDouble(calcFn))));
  </code></pre>
  
  <p><strong>Compile Error</strong>
  The method summingDouble(ToDoubleFunction) in the type Collectors is not applicable for the arguments (Function)</p>
  
  <p>I understand that it needs now function type as <em>ToDoubleFunction</em>, but now issue is how to inject dynamically function into SummingDouble?</p>
  
  <p><strong>Solution</strong> 
  After investigation, i have found following solution. Its not that great and clean as using Function Object. Please update if you have <strong>better</strong> solution to the problem.</p>
  
  <pre><code>        Collectors.summingDouble((o)-&gt;{if(Type.BaseSalary.equals(calculationType)) 
        return o.getBaseSalary();
   else return o.getTotalSalary();
  }))));
  </code></pre>