본문으로 건너뛰기
Skillpedia
일반 코딩48k · #5899

scala

하는 일

이 가이드는 더 효율적이고 명확한 Scala 코드를 작성하는 방법을 가르칩니다. 언어 기능을 사용해 흔한 실수를 피하고, 코드를 읽고 유지하기 쉽게 만드는 예시를 보여 줍니다.

사용하는 경우

  • ✓Scala로 프로그래밍을 배울 때.
  • ✓기존 Scala 코드를 검토할 때.
  • ✓Scala 코드를 개선할 방법을 찾고 있는 경우.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/scala/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/scala/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Scala에서 목록을 다루는 코드를 더 깔끔하게 작성하려면 어떻게 해야 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 가이드는 Scala의 특정 기능을 사용한 '나쁜' 코드 예시와 '좋은' 예시를 비교합니다. 컬렉션, 오류 처리, 기타 모범 사례에 중점을 둡니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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

  1. Collections & Functional Transforms
  2. Pattern Matching
  3. Case Classes & ADTs
  4. Option & Error Handling
  5. Implicits & Given/Using
  6. Concurrency
  7. Anti-patterns specific to Scala

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

// ✅
val found = items.find(_.id == targetId) // returns Option[T]

Use view for lazy evaluation on large collections to avoid intermediate allocations.


2. Pattern Matching {#patterns}

// ❌ if-else chain for type dispatch
if (shape.isInstanceOf[Circle]) {
  val c = shape.asInstanceOf[Circle]
  c.radius * c.radius * Math.PI
} else if (shape.isInstanceOf[Rect]) { ... }

// ✅
shape match {
  case Circle(r) => r * r * Math.PI
  case Rect(w, h) => w * h
}
// ❌ Nested match with identical fallthrough
x match {
  case 1 => "low"
  case 2 => "low"
  case 3 => "mid"
  case _ => "high"
}

// ✅
x match {
  case 1 | 2 => "low"
  case 3     => "mid"
  case _     => "high"
}
// ❌ Match to extract then use
val result = opt match {
  case Some(x) => x.toString
  case None    => "N/A"
}

// ✅
val result = opt.map(_.toString).getOrElse("N/A")
// or:
val result = opt.fold("N/A")(_.toString)

3. Case Classes & ADTs {#case-classes}

// ❌ Regular class for data
class User(val name: String, val age: Int) {
  override def equals(obj: Any): Boolean = ...
  override def hashCode(): Int = ...
  override def toString: String = ...
}

// ✅
case class User(name: String, age: Int)
// ❌ Sealed trait with unrelated case objects
sealed trait Result
case class Success(value: Int) extends Result
case class Failure(error: String) extends Result
case object Unknown extends Result // what does "Unknown" mean?

// ✅ — each variant should carry the data it represents
sealed trait Result[+A]
case class Success[A] (value: A) extends Result[A]
case class Failure(error: Throwable) extends Result[Nothing]
// ❌ (Scala 3) Verbose enum
sealed trait Color
object Color {
  case object Red extends Color
  case object Green extends Color
  case object Blue extends Color
}

// ✅ (Scala 3)
enum Color { case Red, Green, Blue }

4. Option & Error Handling {#option}

// ❌ Null checks
val name: String = if (user != null) user.name else "Unknown"

// ✅
val name = Option(user).map(_.name).getOrElse("Unknown")
// ❌ .get on Option (defeats the purpose)
val name = userOpt.get // throws if None

// ✅
val name = userOpt.getOrElse("default")
// or: userOpt.map(process).getOrElse(fallback)
// or: userOpt match { case Some(u) => ... case None => ... }
// ❌ Try with .get
val result = Try(parse(input)).get // throws on failure

// ✅
val result = Try(parse(input)) match {
  case Success(v) => v
  case Failure(e) => handleError(e)
}
// or: Try(parse(input)).getOrElse(default)
// or: Try(parse(input)).toEither
// ❌ Using exceptions for expected failures
def findUser(id: String): User = {
  val user = db.query(id)
  if (user == null) throw new NotFoundException(id)
  user
}

// ✅ — Option for absence, Either for expected errors
def findUser(id: String): Option[User] = db.query(id)
// or:
def findUser(id: String): Either[AppError, User]

5. Implicits & Given/Using {#implicits}

// ❌ (Scala 2) Implicit conversion that hides bugs

…
자주 묻는 질문

'패턴 매칭'이란 무엇인가요?

구조에서 데이터를 간결하게 확인하고 꺼내는 강력한 방법입니다. 더 똑똑한 'if' 문과 같습니다.

Option에서 '.get'을 피해야 하는 이유는 무엇인가요?

값이 없으면 '.get'은 오류를 일으킬 수 있습니다. 값이 없을 수 있는 경우를 처리하려면 '.getOrElse'나 'match'를 쓰는 것이 낫습니다.

'케이스 클래스'란 무엇인가요?

데이터를 담기 위해 설계된 단순한 클래스입니다. 내장된 비교 기능과 문자열 표현 같은 유용한 기능이 있습니다.

상세 정보

작성자의 원본 설명

Language-specific super-code guidelines for scala.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5899
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬