Run2 scala idiomatic patterns
Idiomatic Scala patterns for translating Python code including enums, case classes, and naming conventions.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run2_scala-idiomatic-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.2 KB, 252 tokens by cl100k_base, as published. Nobody here has run it
Idiomatic Scala Patterns
Enums (Scala 2.13)
Use sealed abstract class with companion object containing case objects:
sealed abstract class TokenType(val value: String)
object TokenType {
case object STRING extends TokenType("string")
}
Case Classes for Immutable Data
- Python
@dataclass(frozen=True)-> Scalacase class - Use
copy()for creating modified instances - Default params replace
field(default_factory=...)
Naming Conventions
- camelCase for methods/fields:
tokenize_batch->tokenizeBatch - PascalCase for types: same in both languages
- Avoid
_prefix for private fields; useprivatemodifier
Avoid var and return
- Use
Optionchains,match, andfoldLeftinstead of mutable vars - Use expression-oriented style: every block returns a value
- Prefer
valovervarwherever possible
Pattern Matching over isinstance
Python isinstance(value, (str, bytes)) becomes Scala pattern matching:
value match {
case s: String => ...
case d: Double => ...
}
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.