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.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- scala-213-type-hierarchy-and-modeling
- description
- Define idiomatic Scala 2.13 type hierarchies and domain models, replacing Python's class structures and Enums with traits and case classes.
03 SKILL.md 正文
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.
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.