Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type definition for combinators (any, first, some) #334

Merged
merged 1 commit into from
Jan 10, 2021
Merged

Improve type definition for combinators (any, first, some) #334

merged 1 commit into from
Jan 10, 2021

Conversation

artemmolotov
Copy link

@artemmolotov artemmolotov commented Dec 11, 2020

This allows to improve type definition. See #305.

You may also be interested in an alternative implementation (@psalm-* attributes only).

Examples:

$promises = [
    $promise1; // - Promise<ExampleClass>
    $promise2; // - Promise<string>
];

[$exceptions, $values] = yield \Amp\Promise\some($promises);

// $exceptions - Throwable[]
// $values     - array<array-key, ExampleClass|string>
$promises = [
    $promise1; // - Promise<int>
    $promise2; // - Promise<bool>
];

[$exceptions, $values] = yield \Amp\Promise\any($promises);

// $exceptions - Throwable[]
// $values     - array<array-key, int|bool>
$promises = [
    $promise1; // - Promise<ExampleClass>
    $promise2; // - Promise<string>
    $promise3; // - Promise<int>
];

$value = yield \Amp\Promise\first($promises);

// $value - ExampleClass|string|int

Amp\Promise\any
Amp\Promise\first
Amp\Promise\some
@artemmolotov artemmolotov changed the title Improve type definition for combinators (any, first, some) [WIP] Improve type definition for combinators (any, first, some) Dec 11, 2020
@kelunik kelunik changed the title [WIP] Improve type definition for combinators (any, first, some) Improve type definition for combinators (any, first, some) Jan 10, 2021
@kelunik kelunik merged commit efca2b3 into amphp:master Jan 10, 2021
@kelunik
Copy link
Member

kelunik commented Jan 10, 2021

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants