/** * This method subscribes a listener. * * @access public * @static * @param IHashMap\Type $xs the left operand * @param ITuple\Type $entry a tuple containing the key and listener * @return IHashMap\Type the map */ public static function subscribe(IHashMap\Type $xs, ITuple\Type $entry) : IHashMap\Type { $k = $entry->first(); $ys = $xs->__hasKey($k) ? $xs->item($k) : ILinkedList\Type::empty_(); $ys = ILinkedList\Module::append($ys, $entry->second()); $zs = IHashMap\Module::putEntry($xs, ITuple\Type::box2($k, $ys)); return $zs; }
/** * This method tests the "nvl" method. */ public function test_nvl() { $x = ILinkedList\Type::make(array(1, 2, 3), '\\Saber\\Data\\IInt32\\Type'); $y = ILinkedList\Type::empty_(); $z = ILinkedList\Module::nvl($x, $y); $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $z); $this->assertSame(array(1, 2, 3), $z->unbox(1)); $z = ILinkedList\Module::nvl(null, $x); $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $z); $this->assertSame(array(1, 2, 3), $z->unbox(1)); $z = ILinkedList\Module::nvl(null, null); $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $z); $this->assertSame(array(), $z->unbox(1)); }
/** * This method tests the "empty" method. */ public function test_empty() { $p0 = ILinkedList\Type::empty_(); $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p0); $this->assertCount(0, $p0->unbox()); }
/** * This method returns the collection as a linked list. * * @access public * @static * @param IArrayList\Type $xs the operand * @return ILinkedList\Type the collection as a linked list */ public static function toLinkedList(IArrayList\Type $xs) : ILinkedList\Type { return IArrayList\Module::foldLeft($xs, function (ILinkedList\Type $c, Core\Type $x) { return ILinkedList\Module::append($c, $x); }, ILinkedList\Type::empty_()); }
/** * This method returns the latter value should the former value evaluates * to null. * * @access public * @static * @param ILinkedList\Type $xs the value to be evaluated * @param ILinkedList\Type $ys the default value * @return ILinkedList\Type the result */ public static function nvl(ILinkedList\Type $xs = null, ILinkedList\Type $ys = null) : ILinkedList\Type { return $xs ?? $ys ?? ILinkedList\Type::empty_(); }