Skip to main content
skill CX Codex

python-scala-syntax-mapping — Claude Code skill: setup and features

python-scala-syntax-mapping is a Claude Code skill that maps Python syntax to Scala for coding assistants translating variables, comprehensions, and control structures.

Apache-2.0 1 installs ★ 1,933 updated 2026-10-24

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add benchflow-ai/skillsbench --skill python-scala-syntax-mapping -a claude-code
Open on GitHub

What python-scala-syntax-mapping does

This skill acts as an explicit translation sheet across language idioms. It pairs core Python types with Scala counterparts, such as converting dict to Map, set to Set, and Optional into Option.

Code examples define how to transform procedural patterns into functional equivalents. Python comprehensions map directly to collection methods like filter or for ... yield blocks. Error handling covers standard block syntax as well as functional handling using scala.util.Try.

The reference specifies using immutable val bindings rather than mutable var unless reassignments are strictly needed.

What it helps with

  • convert Python control flow structures into idiomatic Scala expressions
  • translate list comprehensions into map, filter, or for-comprehensions
  • transform None-checking branches into Scala Option operations
  • substitute Python string formatting with s and f interpolators

Example prompts for the agent

  • Convert this Python function to Scala using Option handling for nullable arguments
  • Rewrite this Python list comprehension into Scala using for-yield syntax
  • Translate this dictionary comprehension and loop into idiomatic Scala code

How to install python-scala-syntax-mapping

1Skills CLI (Vercel)

npx skills add benchflow-ai/skillsbench --skill python-scala-syntax-mapping -a claude-code

2Manually: put the files in place

~/.claude/skills/python-scala-syntax-mapping/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/python-scala-syntax-mapping/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about python-scala-syntax-mapping

How to install python-scala-syntax-mapping in Claude Code?

Run npx skills add benchflow-ai/skillsbench --skill python-scala-syntax-mapping -a claude-code in your terminal.

What does python-scala-syntax-mapping do?

It equips the agent with direct mappings for variables, types, loops, string formatting, and functional pattern matches from Python to Scala.

How does the guide handle Python math operators like ** or //?

Power syntax points to math.pow, while floor division routes to integer division or explicit math.floor calls.

Source text

SKILL.md · Apache-2.0
---
name: python-scala-syntax-mapping
description: Reference guide for translating Python syntax constructs to Scala equivalents. Use when converting Python code to Scala and need mappings for basic syntax elements like variable declarations, control flow, comprehensions, string formatting, and common operators.
---

# Python to Scala Syntax Mapping

## Variable Declarations

| Python | Scala |
|--------|-------|
| `x = 5` | `val x = 5` (immutable) or `var x = 5` (mutable) |
| `x: int = 5` | `val x: Int = 5` |
| `x, y = 1, 2` | `val (x, y) = (1, 2)` |

Prefer `val` over `var` unless mutation is required.

## Type Mappings

| Python | Scala |
|--------|-------|
| `int` | `Int` |
| `float` | `Double` |
| `str` | `String` |
| `bool` | `Boolean` |
| `None` | `None` (of type `Option`) or `null` |
| `list[T]` | `List[T]` or `Seq[T]` |
| `dict[K, V]` | `Map[K, V]` |
| `set[T]` | `Set[T]` |
| `tuple[A, B]` | `(A, B)` or `Tuple2[A, B]` |
| `Optional[T]` | `Option[T]` |

## Control Flow

### Conditionals

```python
# Python
if x > 0:
    result = "positive"
elif x < 0:
    result = "negative"
else:
    result = "zero"
```

```scala
// Scala - if is an expression
val result = if (x > 0) "positive"
             else if (x < 0) "negative"
             else "zero"
```

### Loops

```python
# Python for loop
for i in range(10):
    print(i)

for item in items:
    process(item)

for i, item in enumerate(items):
    print(f"{i}: {item}")
```

```scala
// Scala equivalents
for (i <- 0 until 10) println(i)

for (item <- items) process(item)

for ((item, i) <- items.zipWithIndex) println(s"$i: $item")
```

### While loops

```python
# Python
while condition:
    do_something()
```

```scala
// Scala
while (condition) {
  doSomething()
}
```

## Comprehensions

```python
# Python list comprehension
squares = [x ** 2 for x in range(10)]
evens = [x for x in numbers if x % 2 == 0]
pairs = [(x, y) for x in xs for y in ys]
```

```scala
// Scala for-comprehensions or map/filter
val squares = (0 until 10).map(x => x * x).toList
val evens = numbers.filter(_ % 2 == 0)
val pairs = for { x <- xs; y <- ys } yield (x, y)
```

## Functions

```python
# Python
def add(a: int, b: int) -> int:
    return a + b

# Lambda
square = lambda x: x ** 2

# Default arguments
def greet(name: str, greeting: str = "Hello") -> str:
    return f"{greeting}, {name}!"
```

```scala
// Scala
def add(a: Int, b: Int): Int = a + b

// Lambda
val square: Int => Int = x => x * x
// or shorter: val square = (x: Int) => x * x

// Default arguments
def greet(name: String, greeting: String = "Hello"): String =
  s"$greeting, $name!"
```

## String Formatting

| Python | Scala |
|--------|-------|
| `f"Hello, {name}!"` | `s"Hello, $name!"` |
| `f"Value: {x:.2f}"` | `f"Value: $x%.2f"` |
| `f"{x + y}"` | `s"${x + y}"` |

## Common Operators

| Python | Scala |
|--------|-------|
| `**` (power) | `math.pow(x, y)` or use `scala.math.pow` |
| `//` (floor div) | `x / y` (for Int) or `math.floor(x / y)` |
| `%` (modulo) | `%` |
| `and`, `or`, `not` | `&&`, `||`, `!` |
| `in` | `.contains()` |
| `is` | `eq` (reference equality) |
| `==` | `==` (value equality) |

## Exception Handling

```python
# Python
try:
    result = risky_operation()
except ValueError as e:
    handle_error(e)
finally:
    cleanup()
```

```scala
// Scala
import scala.util.{Try, Success, Failure}

// Pattern 1: try-catch
try {
  val result = riskyOperation()
} catch {
  case e: IllegalArgumentException => handleError(e)
} finally {
  cleanup()
}

// Pattern 2: Try monad (preferred for functional style)
val result = Try(riskyOperation()) match {
  case Success(value) => value
  case Failure(e) => handleError(e)
}
```

## None/Null Handling

```python
# Python
if value is None:
    return default
return process(value)

# Or
result = value if value is not None else default
```

```scala
// Scala - use Option
val result = optionValue match {
  case Some(v) => process(v)
  case None => default
}

// Or more concisely
val result = optionValue.map(process).getOrElse(default)
```

© benchflow-ai · Apache-2.0 · benchflow-ai/skillsbench

Similar skills

All skills for Programming languages →

From the same set22

The whole set →
scipy-curve-fit scipy-curve-fit guides coding agents to estimate nonlinear model parameters from experimental data with scipy.optimize.curve_fit. CX Codex +1 2installs python-scala-idioms python-scala-idioms guides AI agents to translate Python into idiomatic Scala. Enforces immutability, pattern matching, sealed domain traits, and type-safe error handling. CX Codex +1 1installs first-order-model-fitting The first-order-model-fitting skill fits first-order models to experimental step responses and returns K and tau. Use it when you need a compact model of thermal, electrical, or mechanical behavior. CX Codex +1 1installs hex-grid-spatial hex-grid-spatial is a Claude Code skill that calculates neighbours, hex distance, and radius cells on odd-r offset maps for movement or area-of-effect logic. CX Codex +1 1installs image-ocr Use this skill to read text in images with Tesseract OCR through Python. It fits scans, screenshots, and batches of image files. CX Codex +1 1installs audiobook Turns a web article or a text file into an audiobook: pulls the content, cleans it up, and voices it through ElevenLabs, OpenAI TTS or gTTS. CX Codex +1 1installs nanogpt-training nanogpt-training is a Claude Code skill with guidance for training 124M-parameter GPT-2 scale models on a single GPU using Muon, bfloat16, and tokenized dataset shards. CX Codex +1 1installs hierarchical-taxonomy-clustering The hierarchical-taxonomy-clustering skill combines similar category paths from multiple sources into a shared hierarchy. Use it to standardize product categories for cross-source analysis. CX Codex +1 1installs

Project sponsors

Companies that keep this analytics open