Exemplo n.º 1
0
 /**
  * This method evaluates whether the left operand is less than the right operand.
  *
  * @access public
  * @static
  * @param Throwable\Runtime\Exception $x                    the left operand
  * @param Throwable\Runtime\Exception $y                    the right operand
  * @return IBool\Type                                        whether the left operand is less than
  *                                                          the right operand
  */
 public static function lt(Throwable\Runtime\Exception $x, Throwable\Runtime\Exception $y)
 {
     // <
     return IBool\Type::box(Throwable\Runtime\Exception\Module::compare($x, $y)->unbox() < 0);
 }
Exemplo n.º 2
0
 /**
  * This method evaluates whether the left operand is less than the right operand.
  *
  * @access public
  * @static
  * @param IOption\Type $xs                                  the left operand
  * @param IOption\Type $ys                                  the right operand
  * @return IBool\Type                                       whether the left operand is less than
  *                                                          the right operand
  */
 public static function lt(IOption\Type $xs, IOption\Type $ys) : IBool\Type
 {
     // <
     return IBool\Type::box(IOption\Module::compare($xs, $ys)->unbox() < 0);
 }
Exemplo n.º 3
0
 /**
  * This method (aka "null") returns whether this list is empty.
  *
  * @access public
  * @final
  * @return IBool\Type                                       whether the list is empty
  */
 public final function isEmpty() : IBool\Type
 {
     return IBool\Type::box($this->__isEmpty());
 }
Exemplo n.º 4
0
 /**
  * This method tests the "xor_" method.
  */
 public function test_xor_()
 {
     $x = IBool\Type::true();
     $y = IBool\Type::false();
     $z = IBool\Module::xor_($x, $y);
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $z);
     $this->assertSame(true, $z->unbox());
     $z = IBool\Module::xor_($x, $x);
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $z);
     $this->assertSame(false, $z->unbox());
     $z = IBool\Module::xor_($y, $x);
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $z);
     $this->assertSame(true, $z->unbox());
     $z = IBool\Module::xor_($y, $y);
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $z);
     $this->assertSame(false, $z->unbox());
 }
Exemplo n.º 5
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = IBool\Type::box($provided[0])->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Exemplo n.º 6
0
 /**
  * This method evaluates whether the operand is an odd number.
  *
  * @access public
  * @static
  * @param IInt32\Type $x                                    the object to be evaluated
  * @return IBool\Type                                       whether the operand is an odd
  *                                                          number
  */
 public static function isOdd(IInt32\Type $x) : IBool\Type
 {
     return IBool\Type::box($x->unbox() % 2 != 0);
 }
Exemplo n.º 7
0
 /**
  * This method causes the choice block to be closed and executed.
  *
  * @access public
  * @final
  * @return IBool\Type                                       whether a clause has executed
  */
 public final function end() : IBool\Type
 {
     return IBool\Type::box($this->__end());
 }
Exemplo n.º 8
0
 /**
  * This method causes the iterator to advance to the next object.
  *
  * @access public
  * @final
  * @return IBool\Type                                       whether there are more objects
  */
 public final function next() : IBool\Type
 {
     $this->i = IInt32\Module::increment($this->i);
     return IBool\Type::box($this->valid());
 }
Exemplo n.º 9
0
 /**
  * This method (aka "exists" or "some") returns whether some of the items in the collection
  * passed the truthy test.
  *
  * @access public
  * @final
  * @param callable $predicate                               the predicate function to be used
  * @return IBool\Type                                       whether some of the items
  *                                                          passed the truthy test
  */
 public final function any(callable $predicate) : IBool\Type
 {
     return IBool\Type::box($this->either->__isLeft() && $predicate($this->either->item(), IInt32\Type::zero())->unbox());
 }
Exemplo n.º 10
0
 /**
  * This method returns a value as a boxed object.  A value is typically a PHP typed
  * primitive or object.  It is considered type-safe.
  *
  * @access public
  * @static
  * @param mixed $value                                      the value(s) to be boxed
  * @return IBool\Type                                       the boxed object
  */
 public static function make($value) : IBool\Type
 {
     if (is_string($value) && in_array(strtolower($value), array('false', 'f', 'no', 'n', '0', 'null', 'nil'))) {
         return IBool\Type::false();
     }
     return $value ? IBool\Type::true() : IBool\Type::false();
 }
Exemplo n.º 11
0
 /**
  * This method returns whether the operand is a negative number.
  *
  * @access public
  * @static
  * @param IFloat\Type $x                                    the object to be evaluated
  * @return IBool\Type                                       whether the operand is a negative
  *                                                          number
  */
 public static function isNegative(IFloat\Type $x) : IBool\Type
 {
     return IBool\Type::box($x->unbox() < 0.0);
 }
Exemplo n.º 12
0
 /**
  * This method returns whether the operand is a negative number.
  *
  * @access public
  * @static
  * @param IRatio\Type $x                                    the object to be evaluated
  * @return IBool\Type                                       whether the operand is a negative
  *                                                          number
  */
 public static function isNegative(IRatio\Type $x) : IBool\Type
 {
     $a = IInt32\Module::isNegative($x->numerator())->unbox();
     $b = IInt32\Module::isNegative($x->denominator())->unbox();
     return IBool\Type::box(($a || $b) && $a != $b);
 }
Exemplo n.º 13
0
 /**
  * This method returns whether this instance is a "some" option.
  *
  * @access public
  * @final
  * @return IBool\Type                                       whether this instance is a "some"
  *                                                          option
  */
 public final function isDefined() : IBool\Type
 {
     return IBool\Type::box($this->__isDefined());
 }
Exemplo n.º 14
0
 /**
  * This method provides the data for testing the "span" method.
  *
  * @return array
  */
 public function data_span()
 {
     $predicate = function (Core\Boxable\Type $x, IInt32\Type $i) : IBool\Type {
         return IBool\Type::box($x->unbox() < 3);
     };
     $data = array(array(array(array(), $predicate), array(array(), array())), array(array(array(1), $predicate), array(array(1), array())), array(array(array(1, 2), $predicate), array(array(1, 2), array())), array(array(array(1, 2, 3), $predicate), array(array(1, 2), array(3))), array(array(array(1, 2, 3, 4), $predicate), array(array(1, 2), array(3, 4))), array(array(array(1, 3, 2, 4), $predicate), array(array(1), array(3, 2, 4))), array(array(array(3, 1, 4, 2), $predicate), array(array(), array(3, 1, 4, 2))));
     return $data;
 }
Exemplo n.º 15
0
 /**
  * This method evaluates whether the operand is an odd number.
  *
  * @access public
  * @static
  * @param IInteger\Type $x                                  the object to be evaluated
  * @return IBool\Type                                       whether the operand is an odd
  *                                                          number
  */
 public static function isOdd(IInteger\Type $x) : IBool\Type
 {
     return IBool\Type::box(gmp_strval(gmp_div_r($x->unbox(), '2')) != '0');
 }
Exemplo n.º 16
0
 /**
  * This method causes the iterator to advance to the next object.
  *
  * @access public
  * @final
  * @return IBool\Type                                       whether there are more objects
  */
 public final function next() : IBool\Type
 {
     $this->iterator->next();
     return IBool\Type::box($this->valid());
 }
Exemplo n.º 17
0
 /**
  * This method returns whether only one operand is "true".
  *
  * @access public
  * @static
  * @param IBool\Type $x                                     the left operand
  * @param IBool\Type $y                                     the right operand
  * @return IBool\Type                                       whether only one operand is "true"
  *
  * @see http://en.wikipedia.org/wiki/Truth_table#Exclusive_disjunction
  */
 public static function xor_(IBool\Type $x, IBool\Type $y) : IBool\Type
 {
     return IBool\Type::box($x->unbox() xor $y->unbox());
 }
Exemplo n.º 18
0
 /**
  * This method evaluates whether the left operand is less than the right operand.
  *
  * @access public
  * @static
  * @param ITrit\Type $x                                     the left operand
  * @param ITrit\Type $y                                     the right operand
  * @return IBool\Type                                       whether the left operand is less than
  *                                                          the right operand
  */
 public static function lt(ITrit\Type $x, ITrit\Type $y) : IBool\Type
 {
     // <
     return IBool\Type::box(ITrit\Module::compare($x, $y)->unbox() < 0);
 }
Exemplo n.º 19
0
 /**
  * This method returns whether this character is an upper case character.
  *
  * @access public
  * @static
  * @param IChar\Type $x                                     the character to be evaluated
  * @return IBool\Type                                       whether this is an upper case
  *                                                          character
  *
  * @see http://php.net/manual/en/function.ctype-upper.php
  */
 public static function isUpperCase(IChar\Type $x) : IBool\Type
 {
     return IBool\Type::box(ctype_upper($x->unbox()));
 }