Scala Option Either logo

Scala Option Either

Organization
cxcscmu
scala-option-either

Translating Python's None/Optional to Scala's Option, Either, and Try types

Overview

Publishercxcscmu
RepositorySkillLearnBench
Skill namescala-option-either
Stars
91
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cxcscmu on GitHub. Read the source before you install it.

Installation

Install the Scala Option Either AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-option-either
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench.git /tmp/SkillLearnBench
mkdir -p .claude/skills
cp -r /tmp/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-option-either .claude/skills/scala-option-either
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Scala Option Either in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Scala Option Either on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Scala Option Either is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Scala Option, Either, and Try for Python Developers

Core Concept: Functional Error Handling

Python uses None and Optional[T] to represent absence. Scala uses types that can be pattern-matched:

PythonScalaPurpose
NoneNone (in Option)Represents absence
Optional[T] / T | NoneOption[T]Represents presence or absence
Exception handlingEither[Err, Success]Represents error or success
Exception handlingTry[T]Like Either but for exceptions

Option[T] - Replace None/Optional

Python Pattern

python
def safe_divide(a: float, b: float) -> float | None:
    if b == 0:
        return None
    return a / b

result = safe_divide(10, 2)
if result is not None:
    print(f"Result: {result}")
else:
    print("Division by zero")

Scala Pattern

scala
def safeDivide(a: Double, b: Double): Option[Double] =
  if (b == 0) None else Some(a / b)

// Pattern matching
safeDivide(10, 2) match {
  case Some(result) => println(s"Result: $result")
  case None => println("Division by zero")
}

// Or functional style
safeDivide(10, 2).foreach(result => println(s"Result: $result"))

Key Option Methods

scala
val opt: Option[Int] = Some(42)

// Extraction
opt.get        // 42 (throws if None - avoid!)
opt.getOrElse(0)  // 42
opt.orElse(Some(0))  // Some(42)

// Transformation
opt.map(_ * 2)    // Some(84)
opt.flatMap(x => Some(x * 2))  // Some(84)
opt.filter(_ > 40)  // Some(42)

// Iteration
for (v <- opt) println(v)  // prints 42

// Checking
opt.isDefined   // true
opt.isEmpty     // false

Either[L, R] - Represent Success or Failure

Either is more powerful than Option - it carries error information.

Python Pattern

python
def validate_age(age: int) -> tuple[bool, str | None]:
    if age < 0:
        return False, "Age cannot be negative"
    if age > 150:
        return False, "Age seems unrealistic"
    return True, None

success, error = validate_age(-5)
if not success:
    print(f"Error: {error}")

Scala Pattern

scala
def validateAge(age: Int): Either[String, Int] =
  if (age < 0) Left("Age cannot be negative")
  else if (age > 150) Left("Age seems unrealistic")
  else Right(age)

// Pattern matching
validateAge(-5) match {
  case Left(error) => println(s"Error: $error")
  case Right(age) => println(s"Valid age: $age")
}

// Functional style
validateAge(25).map(age => age + 1).foreach(println)

Either is Right-biased (map operates on Right)

scala
val result: Either[String, Int] = Right(5)

result.map(_ * 2)  // Right(10)
result.flatMap(x => Right(x * 2))  // Right(10)
result.leftMap(s => s.toUpperCase)  // Left side transformation
result.fold(
  error => println(s"Error: $error"),  // Left side
  value => println(s"Success: $value")  // Right side
)

Try[T] - For Exception Handling

Try captures exceptions instead of throwing them.

Python Pattern

python
import json

def parse_json(text: str) -> dict:
    try:
        return json.loads(text)
    except json.JSONDecodeError:
        return {}

Scala Pattern

scala
import scala.util.Try
import io.circe.parser._

def parseJson(text: String): Try[Json] =
  parse(text).toTry  // Convert Either to Try

// Or with try-catch
def parseJson(text: String): Try[Map[String, String]] = Try {
  Json.fromString(text).as[Map[String, String]].getOrElse(Map())
}

// Usage
parseJson("{}") match {
  case scala.util.Success(json) => println(s"Parsed: $json")
  case scala.util.Failure(ex) => println(s"Error: ${ex.getMessage}")
}

Chaining Operations

Python Chaining

python
def process(text: str) -> str | None:
    trimmed = text.strip()
    if not trimmed:
        return None

    parts = trimmed.split()
    if not parts:
        return None

    return parts[0].upper()

result = process("  hello world  ")

Scala Chaining with for-comprehension

scala
def process(text: String): Option[String] = for {
  trimmed <- Option(text.trim).filter(_.nonEmpty)
  parts <- Option(trimmed.split("\\s+")).filter(_.nonEmpty)
  first <- Option(parts(0))
} yield first.toUpperCase

// Or with flatMap chain
def process(text: String): Option[String] =
  Option(text.trim)
    .filter(_.nonEmpty)
    .map(_.split("\\s+"))
    .filter(_.nonEmpty)
    .map(_(0).toUpperCase)

Converting Between Types

scala
// Option to Either
val opt: Option[Int] = Some(5)
opt.toRight("Value not found")  // Either[String, Int]

// Either to Option
val either: Either[String, Int] = Right(5)
either.toOption  // Option[Int]

// Try to Either
val attempt: scala.util.Try[Int] = scala.util.Success(5)
attempt.toEither  // Either[Throwable, Int]

// List of Options to Option of List (if all Some)
List(Some(1), Some(2), Some(3)).sequence  // Option[List[Int]]

Pattern in Tokenizer Context

Python (Returns Token | None)

python
def tokenize_path(self, value: JsonValue, path: str) -> Token | None:
    parts = path.split(".")
    current = value

    for part in parts:
        if isinstance(current, dict) and part in current:
            current = current[part]
        else:
            return None

    return self.tokenize(current)

Scala (Returns Option[Token])

scala
def tokenizePath(value: Json, path: String): Option[Token] = {
  val parts = path.split("\\.")
  val finalValue = parts.foldLeft(value) { (current, part) =>
    if (current.isObject) {
      current.hcursor.downField(part).focus.getOrElse(Json.Null)
    } else if (current.isArray) {
      val idx = part.toIntOption.getOrElse(-1)
      if (idx >= 0) current.asArray.flatMap(_.lift(idx)).getOrElse(Json.Null)
      else Json.Null
    } else {
      Json.Null
    }
  }

  if (finalValue == Json.Null) None else Some(tokenize(finalValue))
}

Best Practices

  1. Never use .get on Option - use pattern matching or .getOrElse
  2. Use for comprehensions for multiple Option/Either chains
  3. Leverage .map and .flatMap for transformations
  4. Use Either when you need error information (not just Option)
  5. Use Try when wrapping exception-throwing code
  6. Prefer functional style - map, flatMap, fold instead of pattern matching on every line

Frequently asked questions

What does the Scala Option Either AI skill do?

Translating Python's None/Optional to Scala's Option, Either, and Try types

Why use Scala Option Either on TypingMind?

Because you install it once and use it with any model. Scala Option Either is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Scala Option Either in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/python-scala-translation/scala-option-either. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Scala Option Either?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Scala Option Either?

As many as you like. As long as a model supports skills, you can use Scala Option Either with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Scala Option Either AI skill free?

Yes. It is published on GitHub by cxcscmu under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇