agentsclimarketplace

Run3 scala 213 type hierarchy and modeling

Skill cxcscmu/SkillLearnBench/skills/b3-teacher-feedback-gemini-3-flash-preview/python-scala-translation/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

Install
npx -y skills add cxcscmu/SkillLearnBench --skill run3_scala-213-type-hierarchy-and-modeling

Assembled 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):

  1. Define a sealed trait as the base type.
  2. Define case object instances 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 trait if you only define an interface.
  • Use an abstract class if 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, and toString.
  • A .copy() method, which is essential for the withMetadata pattern.

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.

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.