/** * This method tests the "isPair" method. * * @dataProvider data_isPair */ public function test_isPair(array $provided, array $expected) { $p0 = ITuple\Module::isPair(ITuple\Type::make($provided[0])); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method returns an option containing the value paired with the lookup key x. * * @access public * @static * @param IArrayList\Type $xss the left operand * @param Core\Equality\Type $x the key being looked up * @return IOption\Type an option containing the associated * value * @throws Throwable\UnexpectedValue\Exception indicates that the list is not * associative */ public static function lookup(IArrayList\Type $xss, Core\Equality\Type $x) : IOption\Type { $xssi = IArrayList\Module::iterator($xss); foreach ($xssi as $i => $xs) { if (!ITuple\Module::isPair($xs)->unbox()) { throw new Throwable\UnexpectedValue\Exception('Unable to process tuple. Expected a length of "2", but got a length of ":length".', array(':length' => $xs->__length())); } if ($x->__eq(ITuple\Module::first($xs))) { return IOption\Type::some(ITuple\Module::second($xs)); } } return IOption\Type::none(); }
/** * This method returns the numerically lowest value. * * @access public * @static * @param ITuple\Type $xs the left operand * @param ITuple\Type $ys the right operand * @return ITuple\Type the minimum value */ public static function min(ITuple\Type $xs, ITuple\Type $ys) : ITuple\Type { return ITuple\Module::compare($xs, $ys)->unbox() <= 0 ? $xs : $ys; }
/** * This method returns an option containing the value paired with the lookup key x. * * @access public * @static * @param ILinkedList\Type $xss the left operand * @param Core\Equality\Type $x the key being looked up * @return IOption\Type an option containing the associated * value * @throws Throwable\UnexpectedValue\Exception indicates that the list is not * associative */ public static function lookup(ILinkedList\Type $xss, Core\Equality\Type $x) : IOption\Type { if ($xss->__isEmpty()) { return IOption\Type::none(); } $xs = $xss->head(); if (!ITuple\Module::isPair($xs)->unbox()) { throw new Throwable\UnexpectedValue\Exception('Unable to process tuple. Expected a length of "2", but got a length of ":length".', array(':length' => $xs->__length())); } if ($x->__eq(ITuple\Module::first($xs))) { return IOption\Type::some(ITuple\Module::second($xs)); } return ILinkedList\Module::lookup($xss->tail(), $x); }