Python scala generics
Guidelines for translating Python TypeVars and Protocols to Scala Generics and Traits.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill python-scala-genericsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
0.9 KB, 219 tokens by cl100k_base, as published. Nobody here has run it
Python to Scala Generics Mapping
Variance
- Invariant: Python
TypeVar("T")-> Scala[T] - Covariant: Python
TypeVar("T_co", covariant=True)-> Scala[+T] - Contravariant: Python
TypeVar("T_contra", contravariant=True)-> Scala[-T]
Structural Typing (Protocols)
- Python
Protocol-> Scalatrait. - If structural typing is strictly required in Scala, use "duck typing" via
import scala.language.reflectiveCalls, but standardtraitwith inheritance is preferred for performance and type safety.
Type Bounds
- Python
TypeVar("T", bound=Class)-> Scala[T <: Class] - Python
TypeVar("T", int, float)-> Scala doesn't have Union types in 2.13 in this specific way. UseEither,sealed traithierarchies, or Type Classes (e.g.,Numeric[T]).
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.