scala-generics
Translating Python generic types, variance, and type bounds to Scala 2.13
Skill by cxcscmu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/cxcscmu-scala-generics
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/scala-generics
What's inside
- Skill name
scala-generics- Description
- Translating Python generic types, variance, and type bounds to Scala 2.13
- License
- MIT
- Instructions
- 127 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Scala Generics and Type System for Python Developers
## Core Concepts
### Variance (Key Difference from Python)
Python has no explicit variance system. Scala requires explicit declarations:
**Covariance (+T)** - "out" position, can return subtypes:
```scala
class Container[+T](items: Seq[T]) {
def get: T = items.head // OK - returning subtype
// def set(t: T): Unit // ERROR - would be contravariant
}
```
**Contravariance (-T)** - "in" position, can accept supertypes:
```scala
class Consumer[-T] {
def consume(t: T): Unit // OK - accepting supertype
// def produce: T // ERROR - would be covariant
}
```
**Invariance (T)** - exact type, no variance:
```scala
class Handler[T] {
def get: T
def set(t: T): Unit // Both OK - invariant
}
```
### Translation Pattern
| Python | Scala | Notes |
|--------|-------|-------|
| `TypeVar("T")` | `[T]` | Invariant by default |
| `TypeVar("T_co", covariant=True)` | `[+T]` | Covariant, out-position only |
| `TypeVar("T_contra", contravariant=True)` | `[-T]` | Contravariant, in-position only |
| `TypeVar("T", int, float)` | `[T <: Int \| Float]` | Upper bound (Scala 3) or sealed trait |
| `Generic[T]` | `[T]` | Class definition |
| `Union[A, B]` | `A \| B` (Scala 3) or sealed trait | Use sealed traits for compatibility |
### Type Bounds
```scala
// Upper bound - T must be subtype of Ordered
class Comparable[T <: Ordered[T]]
// Lower bound - T must be supertype of String
class Container[T >: String]
// Context bound (implicit evidence)
class Serializable[T: Format]
```
### Higher-Kinded Types (Scala's advantage)
Python's `TypeVar("F")` for type constructors cannot express true HKTs.
Scala can use type lambdas:
```scala
// Scala 2.13 with kind-projector
type Functor[F[_]] = {
def map[A, B](fa: F[A], f: A => B): F[B]
}
// Or in Scala 3
def map[F[_], A, B](fa: F[A], f: A => B): F[B]
```
## Translation Examples
### Generic Container (Python)
```python
class TokenContainer(Generic[T_co]):
def __init__(self, items: Sequence[T_co]) -> None:
self._items: tuple[T_co, ...] = tuple(items)
def get_all(self) -> tuple[T_co, ...]:
return self._items
```
### Generic Container (Scala 2.13)
```scala
class TokenContainer[+T](items: Seq[T]) {
private val _items: Vector[T] = items.toVector
def getAll: Vector[T] = _items
def size: Int = _items.size
}
```
## Collections Generics
Python uses `Sequence[T]`, `Iterable[T]`, etc. Scala equivalents:
| Python | Scala |
|--------|-------|
| `Sequence[T]` | `Seq[T]` (immutable) |
| `Iterable[T]` | `Iterable[T]` |
| `Iterator[T]` | `Iterator[T]` |
| `list[T]` | `scala.collection.mutable.ListBuffer[T]` or `List[T]` (immutable) |
| `tuple[T, ...]` | `Vector[T]` or `(T, T, ...)` for fixed size |
| `dict[K, V]` | `Map[K, V]` |
## Best Practices for Scala 2.13
1. **Prefer immutable by default** - use `Vector`, `List`, `Map`
2. **Generics in method position** - use `[T]` not just at class level
3. **Variance where appropriate** - adds flexibility but keep simple
4. **Use sealed traits for union types** - more powerful than Python's Union
5. **Type classes for ad-hoc polymorphism** - replaces duck typing
## Working with Circe JSON Types
Circe provides `Json` type which is immutable and generic:
```scalaFrom cxcscmu/SkillLearnBench, MIT.
More from cxcscmu/SkillLearnBench
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
package-lock-parsing
cxcscmu
Parse and extract package information from npm package-lock.json files to identify dependencies and their installed versions.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
trivy-vulnerability-scanning
cxcscmu
Use Trivy vulnerability scanner in offline mode to detect CVEs in npm dependencies and generate structured JSON reports.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
github-metrics-processing
cxcscmu
Process GitHub API data to calculate PR/issue metrics including merge time averages, author rankings, and bug categorization.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
jackson-deserialization-validation
cxcscmu
Securing Jackson JSON deserialization by validating input before processing and preventing unknown properties.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
python-pillow-graphics
cxcscmu
Create technical graphics, diagrams, and posters using Python Pillow library with precise color control and typography.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
git-patch-workflow
cxcscmu
Creating, managing, and applying unified diff patches with Git for source code modifications.
SkillDFreshness: D★ 91Claude Code +9
Signals
- Stars
- 91
- Forks
- 7
- Open issues
- 6
- Last commit (this folder)
- Apr 24, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/cxcscmu/SkillLearnBench
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from cxcscmu
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9
Cite this page
scala-generics skill. Agent Mart. https://agentmart.dev/skills/cxcscmu-scala-generics (last updated 2026-10-24)