Run3 scala 213 type hierarchy and modeling
Define idiomatic Scala 2.13 type hierarchies and domain models, replacing Python's class structures and Enums with traits and case classes.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run3_scala-213-type-hierarchy-and-modelingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.3 KB, 247 tokens by cl100k_base, as published. Nobody here has run it
Sealed Traits and Case Objects for Enums
Scala 2.13 does not support the enum keyword. To represent a fixed set of types (like TokenType):
- Define a
sealed traitas the base type. - Define
case objectinstances for each specific type. This ensures exhaustiveness checking during pattern matching.
Class Hierarchies
Replace Python base classes with a sealed trait or abstract class for the BaseTokenizer.
- Use a
traitif you only define an interface. - Use an
abstract classif you need to provide common constructor parameters or shared logic for all tokenizers.
Data Representation
Use case class for the Token model. Case classes provide:
- Immutability by default.
- Built-in
equals,hashCode, andtoString. - A
.copy()method, which is essential for thewithMetadatapattern.
The withMetadata Pattern
To implement withMetadata idiomatically, leverage the .copy() method of the Token case class. This allows you to return a new instance with updated fields without mutating the original object, maintaining functional purity.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.