Skip to content

disperse() function #3

@rela589n

Description

@rela589n
[$login, $password] = disperse( // could throw CompositeException
    [Login::fromString(...), $loginString], // could throw LoginValidationFailedException
    [Password::fromString(...), $passwordString], // could throw WeakPasswordException
);

Naive implementation is:

function disperse(array ...$tasks): array
{
    foreach ($tasks as [$fn, ...$args]) {
        try {
            $results[] = $fn(...$args);
        } catch (\Throwable $e) {
            $errors[] = $e;
        }
    }
    if ($errors) {
        throw new CompositeException($errors);
    }
    return $results;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions