agentsclimarketplace

Python scala oop

Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-claude-opus-4-6/python-scala-translation/python-scala-oop

Guide for translating Python classes, inheritance, ABC, generics and builder patterns to idiomatic Scala.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill python-scala-oop

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

1.6 KB, 368 tokens by cl100k_base, as published. Nobody here has run it

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
}

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.