scala
Language-specific super-code guidelines for scala.
Scala: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for scala.
Table of Contents
- [Collections & Functional Transforms](#collections)
- [Pattern Matching](#patterns)
- [Case Classes & ADTs](#case-classes)
- [Option & Error Handling](#option)
- [Implicits & Given/Using](#implicits)
- [Concurrency](#concurrency)
- [Anti-patterns specific to Scala](#antipatterns)
1. Collections & Functional Transforms {#collections}
// ❌ Imperative accumulation
val result = new ArrayBuffer[String]()
for (item <- items) {
if (item.isActive) result += item.name.toUpperCase
}
// ✅
val result = items.filter(_.isActive).map(_.name.toUpperCase)
// ❌ Manual grouping
val grouped = mutable.Map[String, List[Item]]()
for (item <- items) {
grouped(item.category) = grouped.getOrElse(item.category, Nil) :+ item
}
// ✅
val grouped = items.groupBy(_.category)
// ❌ Manual fold when sum/product works
var total = 0
for (o <- orders) total += o.amount
// ✅
val total = orders.map(_.amount).sum
// ❌ Using head on potentially empty collection
val first = items.head // throws on empty
// ✅
val first = items.headOption // returns Option[T]
// ❌ Chaining filter + head for find
val found = items.filter(_.id == targetId).head
// ✅
Subscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
