You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying out psalm to get generics for a project of mine.
I started off with the examples and once I thought I understood the concepts I attempted to implement an Option monad because conceptually it feels like an easy generic.
I stumbled accross issues when I was having some static functions and was failing to get 100% coverage so I've tried different ways (interface, one object etc).
Based on my understanding from #8142 psalm templates don't work with static functions.
It works, is expressive and should allow me to have the confidence when mixing functions using them that they'll match correctly.
I'm now wondering if:-
There's a better way to achieve this while maintaining 100% type inference?
The option function always returns Option<T>. Is there a way to make it return/distinguish the subtypes? e.g Some<5> or None<null>. Or should I even care?
How can I track Some<T> but let None have no type? It's a little weird having None<null>. (It's OK as is for me but some purists might argue None shouldn't hold a value which I get.)
Less important, but how is it that it reports 100% yet it always output it's unable to infer types? Even if I have the most basic file, it still says that.
Psalm was unable to infer types in the codebase
100.000% tests/examples/psalm-generics.php (0 mixed)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying out psalm to get generics for a project of mine.
I started off with the examples and once I thought I understood the concepts I attempted to implement an Option monad because conceptually it feels like an easy generic.
I stumbled accross issues when I was having some static functions and was failing to get 100% coverage so I've tried different ways (interface, one object etc).
Based on my understanding from #8142 psalm templates don't work with static functions.
After some more tryouts, this is the solution I got to:
https://psalm.dev/r/49b76986dc
It works, is expressive and should allow me to have the confidence when mixing functions using them that they'll match correctly.
I'm now wondering if:-
Option<T>.
Is there a way to make it return/distinguish the subtypes? e.gSome<5>
orNone<null>.
Or should I even care?Some<T>
but let None have no type? It's a little weird havingNone<null>.
(It's OK as is for me but some purists might argue None shouldn't hold a value which I get.)Less important, but how is it that it reports 100% yet it always output it's unable to infer types? Even if I have the most basic file, it still says that.
Beta Was this translation helpful? Give feedback.
All reactions