Exemplo n.º 1
0
 public static function shrink(callable $f, $roses)
 {
     $roses = FP::realize($roses);
     if (empty($roses)) {
         return self::pure(call_user_func($f));
     } else {
         return new self(call_user_func_array($f, FP::realize(FP::map(FP::method('getRoot'), $roses))), FP::rgen(FP::map(FP::partial([__CLASS__, 'shrink'], $f), self::remove($roses))));
     }
 }
Exemplo n.º 2
0
 /**
  * creates a new generator that passes the result of this generator
  * to the callable $k which should return a new generator.
  *
  * @param callable $k
  * @return Generator
  */
 public function bind(callable $k)
 {
     return $this->bindGen(function (RoseTree $rose) use($k) {
         $gen = new self(function ($rng, $size) use($rose, $k) {
             return $rose->fmap($k)->fmap(FP::method('call', $rng, $size));
         });
         return $gen->fmapGen(FP::method('join'));
     });
 }