agentsclimarketplace

Scala method overloading

Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-gemini-3.1-pro-preview/python-scala-translation/scala-method-overloading

Guide for translating Python @overload and dynamic typing (Any, Union) to Scala method overloading and type matching.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill scala-method-overloading

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

SKILL.md

1.5 KB, 341 tokens by cl100k_base, as published. Nobody here has run it

Method Overloading and Type Matching

Python uses @overload for static type checking but implements dispatch dynamically checking isinstance() at runtime. Scala natively supports method overloading and pattern matching for safe dynamic dispatches.

Translating Union/Overloads

Python:

@overload
def tokenize(self, value: str) -> Token: ...
@overload
def tokenize(self, value: int) -> Token: ...
def tokenize(self, value: Any) -> Token:
    if isinstance(value, str): return Token(value)
    if isinstance(value, int): return Token(str(value))
    return Token(str(value))

Scala:

// Option 1: True method overloading (Preferred when possible)
def tokenize(value: String): Token = Token(value)
def tokenize(value: Int): Token = Token(value.toString)

// Option 2: Pattern Matching on Any (When a generic dispatch method is required)
def tokenize(value: Any): Token = value match {
  case s: String => Token(s)
  case i: Int => Token(i.toString)
  case t: Tokenizable => Token(t.toToken)
  case null => Token("NULL")
  case other => Token(other.toString)
}

Dealing with None and Null

In Scala, null is a bottom type, but it's not idiomatic. However, when interfacing with raw Any parameters, handling null via case null => is common. Otherwise, use Option[T]. To represent a Python parameter that can be None, use an Option type or a default argument.

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.