Skip to content
Agentmart
Submit a tool

scala-option-either

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

Skill by cxcscmu

IndexedMIT★ 91
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/cxcscmu-scala-option-either

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

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

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/scala-option-either

What's inside

Skill name
scala-option-either
Description
Translating Python's None/Optional to Scala's Option, Either, and Try types
License
MIT
Instructions
252 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# 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:

| Python | Scala | Purpose |
|--------|-------|---------|
| `None` | `None` (in Option) | Represents absence |
| `Optional[T]` / `T \| None` | `Option[T]` | Represents presence or absence |
| Exception handling | `Either[Err, Success]` | Represents error or success |
| Exception handling | `Try[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.

From cxcscmu/SkillLearnBench, MIT.

More from cxcscmu/SkillLearnBench

Signals

Stars
91
Forks
7
Open issues
6
Last commit (this folder)
Apr 24, 2026 (6 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from cxcscmu

Cite this page

scala-option-either skill. Agent Mart. https://agentmart.dev/skills/cxcscmu-scala-option-either (last updated 2026-10-24)