public function makeCappuccino()
 {
     return Assembler::create()->ground(function () {
         return $this->grind(new CoffeeBeans("Arabica"));
     })->water(function () {
         return $this->heatWater(new Water(25));
     })->espresso(function ($ground, $water) {
         return $this->brew($ground, $water);
     })->foam(function () {
         return $this->frothMilk(new Milk("skinny"));
     })->combine(function ($espresso, $foam) {
         return $this->combine($espresso, $foam);
     })->assemble()->release('combine', 'ground', 'water', 'foam');
 }
Пример #2
0
 /**
  * Delete an account
  *
  * @param Nominal $nId Id of account
  *
  * @return $this
  * @throws AccountsException
  */
 public function delAccount(Nominal $nId)
 {
     Assembler::create()->accnt(function () use($nId) {
         return $this->tryGetNode($nId, self::ERR_INVALAC)->pass()->flatten();
     })->account(function ($accnt) {
         return FTry::with(function () use($accnt) {
             $account = $accnt->getValue();
             if ($account->getBalance()->get() !== 0) {
                 throw new AccountsException(self::ERR_NODELETE);
             }
             return $account;
         })->pass()->flatten();
     })->transact(function ($account) {
         Match::on(Option::create(($account->getType()->getValue() & AccountType::DR) == AccountType::DR, false))->Monad_Option_Some($account->debit($account->getDebit()->negate()))->Monad_Option_None($account->credit($account->getCredit()->negate()));
     })->removeChild(function ($accnt) {
         $accnt->getParent()->removeChild($accnt);
     })->assemble();
     return $this;
 }
Пример #3
0
 public function testFunctionParametersArePassedInTheCorrectOrder()
 {
     $sut = Assembler::create(['v1' => false, 'v2' => 'foo', 'v3' => new IntType(4)])->foo(function ($v3, $v2, $v1) {
         return $v3() . $v2 . ' ' . ($v1 ? 'true' : 'false');
     })->assemble();
     $this->assertEquals('4foo false', $sut->release('foo'));
 }
 /**
  * @param Assembler $assembler
  * @return Car
  */
 public function make(Assembler $assembler)
 {
     list($tyre, $colour) = $assembler->assemble()->release('tyre', 'colour');
     return new Car("I made you a {$colour} car with {$tyre} tyres");
 }