php-try icon indicating copy to clipboard operation
php-try copied to clipboard

Some API suggestions

Open schmittjoh opened this issue 10 years ago • 2 comments

I've some suggestions for the API after trying this a bit. Basically, I'm wondering what you think about something like this:

Attempt::call($someCallable)
    ->forAll($onSuccess)
    ->always($always) // Finally semantics (called regardless of success/failure)
    ->throwIfFailed()
;

This would be equivalent to:

try {
    $rs = $someCallable();
    $onSuccess($rs);
} finally {
    $always();
}

Not sure if this is already supported in another way, but I haven't found anything. What do you think?

schmittjoh avatar Jan 21 '14 17:01 schmittjoh