Example #1
0
 /**
  * Get counts of items that are new and which ones are completed
  * @return Tuple(int, int, int)
  */
 public static function countNewAndDoneItems() : Tuple
 {
     $countNewAndPast = P::partition(function ($item) {
         $name = $item->state->getShortname();
         return $name === 'expired' || $name === 'completed';
     }, Item::all());
     list($done, $new) = $countNewAndPast;
     $counts = Tuple::create('integer', 'integer');
     return $counts(count($done), count($new));
 }
Example #2
0
 public function testPartition()
 {
     $a = function () {
         (yield 5);
         (yield 8);
         (yield 12);
         (yield 10);
     };
     $is5x = function ($num) {
         return $num % 5 === 0 ? TRUE : FALSE;
     };
     $only5x = P::partition($is5x);
     $this->assertEquals([[5, 10], [8, 12]], $only5x($a()));
 }