public function min_max_sum_average_and_count_for_non_empty()
 {
     Sequence::of([1, 2, 3, 4])->collecting($min, Aggregations::min())->collecting($max, Aggregations::max())->collecting($average, Aggregations::average())->collecting($sum, Aggregations::sum())->collecting($count, Aggregations::count())->each();
     $this->assertEquals(1, $min);
     $this->assertEquals(4, $max);
     $this->assertEquals(2.5, $average);
     $this->assertEquals(10, $sum);
     $this->assertEquals(4, $count);
 }
Esempio n. 2
0
 /**
  * Creates a new collector to calculate an average for all the given elements. Uses
  * the given function to produce a number for each element. If omitted, uses the
  * elements themselves.
  *
  * @param  function(var): var $num
  * @return util.data.ICollector
  */
 public static function averaging($num = null)
 {
     return Aggregations::average($num);
 }