/** * This method tests the "lt" method. * * @dataProvider data_lt */ public function test_lt(array $provided, array $expected) { $p0 = IInt32\Module::lt(IInt32\Type::box($provided[0]), IInt32\Type::box($provided[1])); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method returns each item in this string until the predicate fails. * * @access public * @static * @param IString\Type $xs the left operand * @param callable $predicate the predicate function to be used * @return IString\Type the string */ public static function takeWhile(IString\Type $xs, callable $predicate) : IString\Type { $buffer = ''; $length = $xs->length(); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $x = $xs->item($i); if (!$predicate($x, $i)->unbox()) { break; } $buffer .= $x->unbox(); } return IString\Type::box($buffer); }
/** * This method compares the operands for order. * * @access public * @static * @param ITuple\Type $xs the left operand * @param ITuple\Type $ys the right operand * @return ITrit\Type the order as to whether the left * operand is less than, equals to, * or greater than the right operand */ public static function compare(ITuple\Type $xs, ITuple\Type $ys) : ITrit\Type { $xsl = $xs->length(); $ysl = $ys->length(); $length = IInt32\Module::min($xsl, $ysl); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $r = $xs->item($i)->compare($ys->item($i)); if ($r->unbox() != 0) { return $r; } } return ITrit\Type::box($xsl->unbox() <=> $ysl->unbox()); }