ams-scala-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Scala Pro
Overview
Scala's strength — a principled blend of functional and object-oriented programming on the JVM —
is also its risk: the language lets you write Java-with-sugar, Haskell-on-the-JVM, or anything in
between. Professional Scala means picking a coherent style for the codebase (and sticking to it):
immutable data with case classes, Option/Either instead of nulls/exceptions for expected cases,
for-comprehensions for sequencing, and an effect story the team understands.
The through-line: expressive types, immutable data, explicit effects — and consistency across the codebase.
When to use
- Writing or reviewing Scala for idiom (Scala 2.13 or 3).
- Modeling domains with case classes, ADTs, and pattern matching.
- Choosing effect management (Future, cats-effect, ZIO).
- Structuring Scala projects (sbt, modules, layering).
- Debugging implicits/givens, type inference, or performance issues.
Core concepts
- Case classes + ADTs.
case classfor immutable data (structural equality, pattern matching,copyfor updates);sealed traithierarchies for variants with exhaustive matching. This pair models most domains better than any framework. - Option/Either/Try over nulls and exceptions.
Optionfor absence,Either[E, A]for failures as values, exceptions only for the truly exceptional. For-comprehensions sequence these cleanly — learn to read and write them fluently. - Immutability by default.
valnotvar; immutable collections (List,Vector,Map); transformations return new values.varis occasionally pragmatic (local accumulators, perf hotspots) — never shared mutable state. - Effects, one story.
Futurefor simple async interop (mind the ExecutionContext); cats-effectIOor ZIO for principled effect management with resource safety (Resource/ZManagedfor acquire-release). Don't mix raw Futures and IO in the same codebase without a clear boundary. - Implicits (Scala 2) / givens (Scala 3): powerful, dangerous. Use for typeclass instances and DI-ish context passing; avoid implicit conversions (Scala 3 wisely makes them explicit). When a newcomer can't find where a value comes from, you've overused them.
- Pattern matching as control flow. Destructure in matches, extract with custom extractors
sparingly, and let exhaustiveness checking (
-Xfatal-warnings+ sealed traits) catch missing cases.
Practical workflow
- Scaffold: sbt project, Scala 3 (or 2.13 for legacy ecosystems), scalafmt enforced in CI,
-Xfatal-warningswith-Wunusedto keep the codebase honest. - Model the domain. Sealed traits + case classes; smart constructors (
objectfactories validating input) where invariants matter; no nulls crossing boundaries. - Choose the effect story early. Team decision, documented: plain Futures, cats-effect IO, or ZIO. Consistency beats optimality — a mixed codebase pays both ecosystems' complexity costs.
- Structure in layers. Domain (pure, no effects) → services (effectful orchestration) → interpreters/adapters (DB, HTTP, messaging). The domain stays testable without mocks.
- Test behaviorally. ScalaTest or munit for unit tests, property-based (ScalaCheck) for invariants, and integration tests with real dependencies (testcontainers) at the adapter layer.
- Watch compile times and binary weight. Scala compiles slowly — modularize (sbt subprojects), avoid implicit-heavy megatraits, and profile before blaming the language.
Idiomatic snippets:
// ADT + exhaustive matching
sealed trait OrderStatus
object OrderStatus:
case object Pending extends OrderStatus
case object Paid extends OrderStatus
case object Shipped extends OrderStatus
case object Cancelled extends OrderStatus
def canCancel(s: OrderStatus): Boolean = s match
case OrderStatus.Pending | OrderStatus.Paid => true
case OrderStatus.Shipped | OrderStatus.Cancelled => false
// For-comprehension sequencing Either
def placeOrder(cmd: PlaceCmd): Either[OrderError, Order] =
for
cart <- validateCart(cmd.cart)
priced <- priceCart(cart)
order <- persist(priced)
yield order
Common pitfalls
- Style schizophrenia. Half the codebase in Java-style mutable OO, half in Haskell-style point-free. Agree on the team's Scala dialect (document it) and review for consistency.
- Exceptions for expected failures. Throwing for validation errors or "not found" in normal
flow.
Either/Optionfor expected cases; exceptions for programmer errors and truly exceptional infrastructure failures. nullleaking in. From Java interop or careless code — wrap Java APIs at the boundary (Option(x)), never let null flow through Scala code.- Implicit/given soup. Instances and conversions that make code magical and undebuggable. Explicit is better than implicit when the reader can't trace the source.
- Blocking in Futures. Calling blocking I/O inside the default ExecutionContext starves it. Dedicated (blocking) context for blocking calls, or an effect system that manages shifting.
- Over-abstracted typelevel gymnastics. Shapeless/HList wizardry and 5-parameter typeclasses for business CRUD. The type system serves the domain — when the types are harder than the problem, simplify.
- Ignoring compile-time cost. Massive implicit resolution and macro expansion making builds take 20 minutes. Modularize, reduce implicit scope, and treat build time as a team tax.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).