Ejemplo n.º 1
0
 /**
  * This method publishes the message to any subscribed listerners.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param ITuple\Type $message                              a tuple containing the event key and
  *                                                          value to be published
  * @return IHashMap\Type                                    the map
  */
 public static function publish(IHashMap\Type $xs, ITuple\Type $message) : IHashMap\Type
 {
     $k = $message->first();
     if ($xs->hasKey($k)) {
         ILinkedList\Module::each($xs->item($k), function (callable $y) use($message) {
             $y($message->second());
         });
     }
     return $xs;
 }
Ejemplo n.º 2
0
 /**
  * This method tests the "each" method.
  *
  * @dataProvider data_each
  */
 public function test_each(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type');
     $e0 = $expected[0];
     $e1 = 0;
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p0);
     $this->assertCount(count($e0), $p0->unbox());
     $p1 = ILinkedList\Module::each($p0, function ($x, $i) use($e0, &$e1) {
         $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $i);
         $this->assertSame($e1, $i->unbox());
         $this->assertInstanceOf('\\Saber\\Core\\Type', $x);
         $this->assertSame($e0[$e1], $x->unbox());
         $e1++;
     });
     $this->assertCount($e1, $e0);
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p1);
     $this->assertSame($e0, $p1->unbox(1));
 }