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

Fix Either::flatMap signature #45

Merged
merged 1 commit into from
Dec 14, 2021
Merged

Fix Either::flatMap signature #45

merged 1 commit into from
Dec 14, 2021

Conversation

klimick
Copy link
Contributor

@klimick klimick commented Dec 14, 2021

/**
 * @return Either<int, stdClass>
 */
function doSomething(mixed $_param): Either
{
    throw new RuntimeException('???');
}

/**
 * @return Either<string, stdClass>
 */
function findSomething(): Either
{
    throw new RuntimeException('???');
}

/**
 * @return Either<string|int, stdClass>
 */
function app(): Either
{
    /**
     * ERROR: InvalidScalarArgument
     * at /some-path/run.php:26:19
     *   Argument 1 of Either::flatMap
     *      expects callable(stdClass):Either<string, mixed>
     *      provided impure-Closure(stdClass):Either<int, stdClass> (see https://psalm.dev/012)
     */
    return findSomething()
        ->flatMap(fn($something) => doSomething($something));
}

@whsv26 whsv26 merged commit 03e76ae into fp4php:master Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants