Пример #1
0
 /**
  * This method returns a "cons" object for a choice.
  *
  * @access public
  * @static
  * @param Core\Equality\Type $x                             the object to be evaluated
  * @param Control\Choice\Type $xs                           the tail
  * @return Control\Choice\Type                              the "cons" object
  */
 public static function cons(Core\Equality\Type $x, Control\Choice\Type $xs) : Control\Choice\Type
 {
     if ($xs !== null) {
         return new Control\Choice\Cons\Type($x, $xs);
     }
     return new Control\Choice\Cons\Type($x, Control\Choice\Type::nil());
 }
Пример #2
0
 /**
  * This method sets the procedure that will be executed should "y" equal "x".
  *
  * @access public
  * @final
  * @param Core\Equality\Type $y                             the object to be evaluated
  *                                                          against
  * @param callable $procedure                               the procedure to be executed
  * @return Control\Choice\Type                              a reference to the next choice
  *                                                          monad node
  */
 public final function when(Core\Equality\Type $y, callable $procedure) : Control\Choice\Type
 {
     $this->predicate = function ($x) use($y, $procedure) {
         if ($y->__eq($x)) {
             IUnit\Type::covariant($procedure($x));
             return true;
         }
         return false;
     };
     return Control\Choice\Type::cons($this->x, $this);
 }
Пример #3
0
 /**
  * This method returns a choice monad for evaluating an object.
  *
  * @access public
  * @static
  * @param Core\Equality\Type $x                             the object to be evaluated
  * @return Control\Choice\Type                              the choice monad
  */
 public static function choice(Core\Equality\Type $x) : Control\Choice\Type
 {
     return Control\Choice\Type::cons($x, Control\Choice\Type::nil());
 }