Skip to content

Some API suggestions #2

Description

@schmittjoh

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions