python-scala-oop
Guide for translating Python classes, inheritance, ABC, generics and builder patterns to idiomatic Scala.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- python-scala-oop
- description
- Guide for translating Python classes, inheritance, ABC, generics and builder patterns to idiomatic Scala.
03 SKILL.md 正文
Python to Scala OOP Patterns
Abstract Base Class -> Abstract Class or Trait
// Python: class BaseTokenizer(ABC, Generic[T])
// Scala:
abstract class BaseTokenizer[T] {
def tokenize(value: T): Token
def tokenizeBatch(values: Iterable[T]): Iterator[Token] =
values.iterator.map(tokenize)
}
Generic Classes with Variance
// Covariant container (produces T)
class TokenContainer[+T](items: Seq[T]) {
private val _items: Vector[T] = items.toVector
def getAll: Vector[T] = _items
}
// Contravariant sink (consumes T)
class TokenSink[-T] { ... }
// Invariant handler
class BivariantHandler[T](private var _value: T) { ... }
Builder Pattern (Fluent Interface)
// Use `this.type` or return the class itself for chaining
class TokenizerBuilder[T] {
def withNormalizer(f: String => String): TokenizerBuilder[T] = { ... ; this }
def build(): T => Token = { ... }
}
// Companion object with apply for factory
object TokenizerBuilder {
def apply[T](): TokenizerBuilder[T] = new TokenizerBuilder[T]
}
Mutable State
// Python: @dataclass with mutable fields
// Scala: use var or mutable collections explicitly
import scala.collection.mutable
class MutableTokenBatch {
private val _tokens = mutable.ListBuffer.empty[Token]
private var _processed = false
def add(token: Token): Unit =
if (_processed) throw new RuntimeException("Batch already processed")
else _tokens += token
}
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.