Example #1
0
 /**
  * @test
  */
 public function it_returns_Failure_if_the_callable_thrown()
 {
     $failure = Attempt::call(function () {
         throw new Exception();
     });
     $this->assertInstanceOf('PhpTry\\Failure', $failure);
 }
 protected function createFailure($exception)
 {
     $callable = function () use($exception) {
         throw $exception;
     };
     return Attempt::lazily($callable);
 }
 protected function createSuccess($value)
 {
     $callable = function () use($value) {
         return $value;
     };
     return Attempt::lazily($callable);
 }
Example #4
0
 /**
  * @test
  */
 public function it_does_not_call_the_callable_immediately()
 {
     $called = false;
     $attempt = Attempt::lazily(function () use(&$called) {
         $called = true;
     });
     $this->assertFalse($called);
 }
Example #5
0
function promptDivide()
{
    $a = prompt("Enter a number (a) that you'd like to divide:");
    $b = prompt("Enter a number (b) that you'd like to divide by:");
    $c = prompt("Enter a number (c) that you'd like to multiply by:");
    return Attempt::call('divide', array($a, $b))->map(function ($elem) use($c) {
        return multiply($elem, $c);
    });
}
Example #6
0
 public function map($callable)
 {
     return Attempt::call($callable, array($this->value));
 }
Example #7
0
 public function recover($callable)
 {
     return Attempt::call($callable, array($this->exception));
 }