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

Better pipe plugin #8

Merged
merged 1 commit into from Dec 5, 2022
Merged

Conversation

veewee
Copy link
Collaborator

@veewee veewee commented Nov 30, 2022

Psalm v5 is out!

This PR contains:

  • a pipe plugin through the new dynamic storage provider plugin system

More info about the dynamic storage:

-> Testcases in PSL: azjezz/psl#372

Why is this better?

The newly introduced DynamicFunctionStorageProviderInterface makes it possible to dynamically create templates based on the provided function. This allows us to count the amount of arguments (e.g. 3) and create 4 dynamic templates that are linking up the pipe parameters like this:

  • param1 = closure(T1): T2
  • param2 = closure(T2): T3
  • param3 = closure(T3): T4

The resulting closure that is coming out pipe() will then be:

  • closure(T1): T4

In previous implementation, we frequently had to tell psalm the types were mixed, because we did not know better.
By doing it this way, we rely on psalm being able to infer the templates for us!

(Thanks to the amazing work of @klimick)

Possible other use-case

Based on this principle, we can add e.g. new partial_left and partial_right functions that are checked by psalm instead of runtime. I would only add this if we were able to use the function as string (e.g. through dynamic define's as you proposed a while back.
For example:

partial_right(Vec\map, Str\trim)($items) // -> closure(list<string>): list<string>

// or

partial_right(Vec\map::class, Str\trim::class)($items)

More info:

The cool thing about validating this in psalm, is that we do not require additional runtime validations. (or at least theoretically)

@veewee veewee changed the title Better pipe plugin + psalm v5 changes [WIP] Better pipe plugin + psalm v5 changes Nov 30, 2022
@veewee veewee changed the title [WIP] Better pipe plugin + psalm v5 changes [WIP] Better pipe plugin Nov 30, 2022
@veewee veewee marked this pull request as draft November 30, 2022 18:49
@veewee veewee force-pushed the better-pipe branch 2 times, most recently from 02b9e19 to 6a46bb9 Compare December 5, 2022 15:22
@veewee veewee changed the title [WIP] Better pipe plugin Better pipe plugin Dec 5, 2022
Copy link
Contributor

@azjezz azjezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

@azjezz azjezz merged commit 6135693 into php-standard-library:main Dec 5, 2022
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.

None yet

2 participants