agentsclimarketplace

Python scala sealed enum

Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-claude-sonnet-4-6/python-scala-translation/python-scala-sealed-enum

Translating Python Enum classes to Scala sealed abstract classes or sealed traits with companion objects, preserving value fields and exhaustive pattern matching.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill python-scala-sealed-enum

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

SKILL.md

1.9 KB, 417 tokens by cl100k_base, as published. Nobody here has run it

Python Enum → Scala Sealed Traits

Python Pattern

class TokenType(Enum):
    STRING = "string"
    NUMERIC = "numeric"
    NULL = "null"

Scala Idiomatic Translation

Use sealed abstract class (not Enum) with a companion object holding case object members:

sealed abstract class TokenType(val value: String)

object TokenType {
  case object STRING  extends TokenType("string")
  case object NUMERIC extends TokenType("numeric")
  case object NULL    extends TokenType("null")
}

Why sealed abstract class over sealed trait?

  • Use sealed abstract class when members need constructor parameters (like value: String).
  • Use sealed trait for purely marker/tag types with no data.

Key Differences from Python

PythonScala
TokenType.STRING.valueTokenType.STRING.value (same API)
isinstance(x, TokenType)Pattern match on sealed type
Can iterate list(TokenType)Use Set(STRING, NUMERIC, ...) manually
TokenType["STRING"]Not needed; use TokenType.STRING directly

Exhaustive Pattern Matching (Bonus)

def describe(t: TokenType): String = t match {
  case TokenType.STRING  => "A string token"
  case TokenType.NUMERIC => "A numeric token"
  case TokenType.NULL    => "A null token"
  // Compiler warns if a case is missing (because sealed)
}

Companion Object values List (if needed)

object TokenType {
  case object STRING  extends TokenType("string")
  case object NUMERIC extends TokenType("numeric")
  case object NULL    extends TokenType("null")

  val values: List[TokenType] = List(STRING, NUMERIC, NULL)

  def fromString(s: String): Option[TokenType] =
    values.find(_.value == s)
}

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.