agentsclimarketplace

Scala type variance

Skill cxcscmu/SkillLearnBench/skills/b4-skill-creator-gemini-3.1-pro-preview/python-scala-translation/scala-type-variance

Translating Python TypeVar variance to Scala. Use this skill whenever you see T_co or T_contra in Python and need to write equivalent Scala traits or classes.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill scala-type-variance

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

1.1 KB, 274 tokens by cl100k_base, as published. Nobody here has run it

Scala Type Variance

  • Python TypeVar("T_co", covariant=True) -> Scala [+T] (Covariant).
  • Python TypeVar("T_contra", contravariant=True) -> Scala [-T] (Contravariant).
  • Python TypeVar("T") -> Scala [T] (Invariant).

Invariance, Covariance, Contravariance rules in Scala

  • Covariant types [+T] can only appear in covariant positions (e.g., return types of methods). If you need to accept T in a method parameter, use a lower type bound: def method[U >: T](val: U).
  • Contravariant types [-T] can only appear in contravariant positions (e.g., arguments of methods). If you need to return T, use an upper type bound: def method[U <: T](): U.
  • Mutable collections (like ArrayBuffer or mutable.Map) are invariant [T].
  • Immutable collections (like List, Vector) are covariant [+T].
  • Scala functions A => B are contravariant in A and covariant in B: [-A, +B].

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.