Skip to content
Skills Library
Programming · Conversion & formats

python-scala-enums-adts

/python-scala-enums-adts

Translating Python enums, dataclasses, and union types to Scala sealed traits, case classes, and ADTs. Use when converting Python Enum classes to Scala enumerations, Python dataclasses to Scala case classes, or Python Union/Optional types to Scala Option/Either/sealed hierarchies.

Licence
MIT
Last repository change
02.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 02.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Translating Python enums, dataclasses, and union types to Scala sealed traits, case classes, and ADTs. Use when converting Python Enum classes to Scala enumerations, Python dataclasses to Scala case classes, or Python Union/Optional types to Scala Option/Either/sealed hierarchies.

Original author description

Translating Python enums, dataclasses, and union types to Scala sealed traits, case classes, and ADTs. Use when converting Python Enum classes to Scala enumerations, Python dataclasses to Scala case classes, or Python Union/Optional types to Scala Option/Either/sealed hierarchies.

How it works

  1. Python Enum → Scala sealed abstract class + case objects
  2. Python dataclass(frozen=True) → Scala case class
  3. Python @dataclass (mutable) → Scala class with vars or mutable buffer
  4. Python Optional/Union → Scala Option/Either
Original SKILL.md headings · 70 lines, 262 words
SKILL.md preview
---
name: python-scala-enums-adts
description: >
  Translating Python enums, dataclasses, and union types to Scala sealed traits,
  case classes, and ADTs. Use when converting Python Enum classes to Scala enumerations,
  Python dataclasses to Scala case classes, or Python Union/Optional types to Scala
  Option/Either/sealed hierarchies.
---

# Python Enums & Dataclasses to Scala ADTs

## Python Enum → Scala sealed abstract class + case objects

Python:
```python
class TokenType(Enum):
    STRING = "string"
    NUMERIC = "numeric"
```

Scala (2.13 idiomatic):
```scala
sealed abstract class TokenType(val value: String)
object TokenType {
  case object STRING extends TokenType("string")
  case object NUMERIC extends TokenType("numeric")
}
```

Why sealed abstract class: Scala 2.13 doesn't have `enum` (that's Scala 3). A sealed hierarchy gives exhaustive match checking and is the standard Scala 2 pattern.

## Python dataclass(frozen=True) → Scala case class

Python:
```python
@dataclass(frozen=True)
class Token:
    value: str
    token_type: TokenType
    metadata: dict[str, Any] = field(default_factory=dict)
```

Scala:
```scala
case class Token(
  value: String,
  tokenType: TokenType,
  metadata: Map[String, Any] = Map.empty
)
```

Key differences:
- Case classes are immutable by default (no `frozen` needed)
- `field(default_factory=dict)` becomes `= Map.empty` — Scala's default args are evaluated fresh each call
- Use `camelCase` for field names per Scala convention
- `copy()` is auto-generated and replaces manual `with_metadata` style methods, though a convenience method can wrap it

## Python @dataclass (mutable) → Scala class with vars or mutable buffer

For mutable state, use `var` fields or mutable collections, and throw `IllegalStateException` for state violations:
```scala
class MutableTokenBatch {
  private val _tokens = scala.collection.mutable.ListBuffer.empty[Token]
  private var _processed = false

  def add(token: Token): Unit = {
    if (_processed) throw new IllegalStateException("Batch already processed")
    _tokens += token
  }
}
```

## Python Optional/Union → Scala Option/Either

- `Optional[X]` / `X | None` → `Option[X]`
- `Union[A, B]` → `Either[A, B]` or a sealed trait hierarchy
- `dict[str, Any]` → `Map[String, Any]`

Versions

The database has no other skills named python-scala-enums-adts.

Database snapshot: 13.11.2026 · package version c718b7d417e7 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100scala-immutable-data
    How to convert Python mutable dataclasses and enums to immutable Scala case classes, sealed traits, and sealed objects. Use when translating Python @dataclass, Enum, and mutable collection patterns to idiomatic Scala. Covers immutable-by-default patterns, copy with…
  • 95python-scala-sealed-traits
    Guide for translating Python Enum, Protocol, and abstract class hierarchies to Scala sealed trait hierarchies. Use this skill whenever converting Python Enum classes, runtime-checkable Protocol types, abstract base classes (ABC), or Union type aliases to idiomatic Scala sealed…
  • 90vibe-types:scala
    Scala 3 compile-time safety techniques — opaque types, enums/ADTs/GADTs, givens, match types, inline, capture checking. Use this skill whenever the user writes Scala 3 code, mentions type safety, asks about compiler errors, discusses ADTs, opaque types, given instances, context…
  • 95python-scala-oop
    Guide for translating Python classes, inheritance, and object-oriented patterns to Scala. Use when converting Python code with classes, dataclasses, abstract classes, inheritance, properties, static methods, class methods, or design patterns.
  • 100python-scala-idioms
    Guide for writing idiomatic Scala when translating from Python. Use when the goal is not just syntactic translation but producing clean, idiomatic Scala code. Covers immutability, expression-based style, sealed hierarchies, and common Scala conventions.
  • 95lang-scala
    Use this skill when the user says 'Scala', 'Scala 3', 'sbt', 'scala-cli', 'given/using', 'implicits', 'type classes', 'opaque types', 'ADT enum', 'Cats Effect', 'ZIO', 'Pekko', 'Akka', 'Spark Scala', 'for-comprehension', 'munit'. Writes and reviews idiomatic Scala 3 (and Scala…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.