/** * @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); }
/** * @test */ public function it_does_not_call_the_callable_immediately() { $called = false; $attempt = Attempt::lazily(function () use(&$called) { $called = true; }); $this->assertFalse($called); }
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); }); }
public function map($callable) { return Attempt::call($callable, array($this->value)); }
public function recover($callable) { return Attempt::call($callable, array($this->exception)); }