/** * @test */ public function it_returns_Failure_if_the_callable_thrown() { $failure = Attempt::call(function () { throw new Exception(); }); $this->assertInstanceOf('PhpTry\\Failure', $failure); }
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)); }