Example #1
0
 static function defStatic($name, $closure)
 {
     $table = get_called_class();
     if (!DispatchTable::tableExists($table)) {
         DispatchTable::createTable($table);
     }
     DispatchTable::addToTable($table, $name, rawr_reduce($closure, rawr_callable));
 }
Example #2
0
 public function ifFalse($f)
 {
     $left = $this->value;
     $right = NULL;
     if (!left) {
         $right = rawr_reduce($f, rawr_callable);
         call_user_func($right);
     }
     return $this;
 }
Example #3
0
 /**
  * Function composition, where `(f · g)(x) = f(g(x))`.
  * @author Marcelo Camargo
  * @param callable $fn
  * @return Action
  */
 public function ·($fn)
 {
     $left = $this;
     $right = $fn;
     if (!is_callable($right)) {
         throw new \Exception("[rawr-core] Not a function");
     }
     $size_l = rawr_reduce($this->getRemainingParameters(), rawr_integer);
     $size_r = NULL;
     // Get size of the received function
     if ($right instanceof \Rawr\DataType\Action) {
         $size_r = rawr_reduce($right->getRemainingParameters(), rawr_integer);
     } else {
         $size_r = (new ReflectionFunction($right))->getNumberOfRequiredParameters();
     }
     if ($size_l > $size_r) {
         throw new \Exception("[rawr-core] Left function cannot have greater arity than right");
     }
     if ($size_l > 1) {
         throw new \Exception("[rawr-core] Left function only receives 1 parameter");
     }
     return new Action(function () use($left, $right) {
         $arguments = func_get_args();
         return call_user_func_array($left, [call_user_func_array($right, $arguments)]);
     });
 }