moai-lang-scala

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scala 3.4+ Development Specialist

Scala 3.4+开发专家

Functional programming, effect systems, and big data processing for JVM applications.
面向JVM应用的函数式编程、效应系统及大数据处理方案。

Quick Reference

快速参考

Auto-Triggers: Scala files (.scala, .sc), build files (build.sbt, project/build.properties)
Core Capabilities:
  • Scala 3.4: Given/using, extension methods, enums, opaque types, match types
  • Akka 2.9: Typed actors, streams, clustering, persistence
  • Cats Effect 3.5: Pure FP runtime, fibers, concurrent structures
  • ZIO 2.1: Effect system, layers, streaming, error handling
  • Apache Spark 3.5: DataFrame API, SQL, structured streaming
Key Ecosystem Libraries:
  • HTTP: Http4s 0.24, Tapir 1.10
  • JSON: Circe 0.15, ZIO JSON 0.6
  • Database: Doobie 1.0, Slick 3.5, Quill 4.8
  • Streaming: FS2 3.10, ZIO Streams 2.1
  • Testing: ScalaTest, Specs2, MUnit, Weaver

自动触发场景:Scala文件(.scala、.sc)、构建文件(build.sbt、project/build.properties)
核心能力:
  • Scala 3.4:Given/using语法、扩展方法、枚举、不透明类型、匹配类型
  • Akka 2.9:类型化Actor、流处理、集群、持久化
  • Cats Effect 3.5:纯函数式FP运行时、纤程、并发结构
  • ZIO 2.1:效应系统、层(Layers)、流处理、错误处理
  • Apache Spark 3.5:DataFrame API、SQL、结构化流处理
关键生态库:
  • HTTP:Http4s 0.24、Tapir 1.10
  • JSON:Circe 0.15、ZIO JSON 0.6
  • 数据库:Doobie 1.0、Slick 3.5、Quill 4.8
  • 流处理:FS2 3.10、ZIO Streams 2.1
  • 测试:ScalaTest、Specs2、MUnit、Weaver

Module Index

模块索引

This skill uses progressive disclosure with specialized modules:
本技能采用渐进式披露机制,包含以下专业模块:

Core Language

核心语言

  • functional-programming.md - Scala 3.4 features: Given/Using, Type Classes, Enums, Opaque Types, Extension Methods
  • functional-programming.md - Scala 3.4特性:Given/Using、类型类、枚举、不透明类型、扩展方法

Effect Systems

效应系统

  • cats-effect.md - Cats Effect 3.5: IO monad, Resources, Fibers, FS2 Streaming
  • zio-patterns.md - ZIO 2.1: Effects, Layers, ZIO Streams, Error handling
  • cats-effect.md - Cats Effect 3.5:IO monad、资源管理、纤程、FS2流处理
  • zio-patterns.md - ZIO 2.1:效应、层、ZIO流处理、错误处理

Frameworks

框架

  • akka-actors.md - Akka Typed Actors 2.9: Actors, Streams, Clustering patterns
  • spark-data.md - Apache Spark 3.5: DataFrame API, SQL, Structured Streaming

  • akka-actors.md - Akka 2.9类型化Actor:Actor、流处理、集群模式
  • spark-data.md - Apache Spark 3.5:DataFrame API、SQL、结构化流处理

Implementation Guide

实现指南

Project Setup (SBT 1.10)

项目搭建(SBT 1.10)

In build.sbt, set ThisBuild / scalaVersion to "3.4.2" and organization. Define lazy val root project with settings including name and libraryDependencies. Add dependencies for cats-effect, zio, akka-actor-typed, http4s-ember-server, circe-generic, and scalatest for test scope. Include scalacOptions for deprecation, feature warnings, and Xfatal-warnings.
在build.sbt中,设置ThisBuild / scalaVersion为"3.4.2"并指定组织名。定义lazy val根项目,包含名称、libraryDependencies等配置。添加cats-effect、zio、akka-actor-typed、http4s-ember-server、circe-generic等依赖,以及测试范围的scalatest。配置scalacOptions以启用弃用警告、特性警告及Xfatal-warnings。

Quick Examples

快速示例

Extension Methods: Use extension keyword with parameter in parentheses. Define methods like words splitting on whitespace and truncate checking length before taking characters and appending ellipsis.
Given and Using: Define trait with abstract method signature. Create given instance with with keyword and implement the method. Create functions with using parameter clause for implicit resolution.
Enum Types: Define enum with generic type parameters and plus variance annotations. Create case entries with parameters. Define methods on enum using match expression to handle each case, returning appropriate results.

扩展方法:使用extension关键字并在括号中指定参数。定义如按空格拆分单词的words方法,以及先检查长度再截取字符并添加省略号的truncate方法。
Given和Using:定义带有抽象方法签名的trait。使用with关键字创建given实例并实现该方法。创建带有using参数子句的函数以实现隐式解析。
枚举类型:定义带有泛型参数和协变注解的enum。创建带参数的case条目。使用match表达式在enum上定义方法,处理每个case并返回相应结果。

Context7 Integration

Context7集成

Library mappings for latest documentation:
Core Scala:
  • /scala/scala3 - Scala 3.4 language reference
  • /scala/scala-library - Standard library
Effect Systems:
  • /typelevel/cats-effect - Cats Effect 3.5 documentation
  • /typelevel/cats - Cats 2.10 functional abstractions
  • /zio/zio - ZIO 2.1 documentation
  • /zio/zio-streams - ZIO Streams 2.1
Akka Ecosystem:
  • /akka/akka - Akka 2.9 typed actors and streams
  • /akka/akka-http - Akka HTTP REST APIs
  • /akka/alpakka - Akka connectors
HTTP and Web:
  • /http4s/http4s - Functional HTTP server/client
  • /softwaremill/tapir - API-first design
Big Data:
  • /apache/spark - Spark 3.5 DataFrame and SQL
  • /apache/flink - Flink 1.19 streaming
  • /apache/kafka - Kafka clients 3.7

最新文档的库映射:
Scala核心:
  • /scala/scala3 - Scala 3.4语言参考
  • /scala/scala-library - 标准库
效应系统:
  • /typelevel/cats-effect - Cats Effect 3.5文档
  • /typelevel/cats - Cats 2.10函数式抽象
  • /zio/zio - ZIO 2.1文档
  • /zio/zio-streams - ZIO Streams 2.1
Akka生态:
  • /akka/akka - Akka 2.9类型化Actor及流处理
  • /akka/akka-http - Akka HTTP REST API
  • /akka/alpakka - Akka连接器
HTTP与Web:
  • /http4s/http4s - 函数式HTTP服务器/客户端
  • /softwaremill/tapir - API优先设计
大数据:
  • /apache/spark - Spark 3.5 DataFrame与SQL
  • /apache/flink - Flink 1.19流处理
  • /apache/kafka - Kafka客户端3.7

Testing Quick Reference

测试快速参考

ScalaTest: Extend AnyFlatSpec with Matchers. Use string description with should in for behavior. Make assertions with shouldBe for equality checks.
MUnit with Cats Effect: Extend CatsEffectSuite. Define test with string name. Return IO containing assertEquals assertions.
ZIO Test: Extend ZIOSpecDefault. Define spec as suite with test entries. Use for-comprehension to run effects and yield assertTrue assertions.

ScalaTest:继承AnyFlatSpec并混入Matchers。使用字符串描述+should in的形式定义行为。用shouldBe进行相等性断言。
结合Cats Effect的MUnit:继承CatsEffectSuite。用字符串名称定义测试。返回包含assertEquals断言的IO。
ZIO Test:继承ZIOSpecDefault。将spec定义为包含测试条目的套件。使用for推导式运行效应并返回assertTrue断言。

Troubleshooting

故障排除

Common Issues:
  • Implicit resolution: Use scalac -explain for detailed error messages
  • Type inference: Add explicit type annotations when inference fails
  • SBT slow compilation: Enable Global / concurrentRestrictions in build.sbt
Effect System Issues:
  • Cats Effect: Check for missing import cats.effect._ or import cats.syntax.all._
  • ZIO: Verify layer composition with ZIO.serviceWith and ZIO.serviceWithZIO
  • Akka: Review actor hierarchy and supervision strategies

常见问题:
  • 隐式解析:使用scalac -explain获取详细错误信息
  • 类型推断:当推断失败时添加显式类型注解
  • SBT编译缓慢:在build.sbt中启用Global / concurrentRestrictions
效应系统问题:
  • Cats Effect:检查是否缺少import cats.effect.或import cats.syntax.all.
  • ZIO:使用ZIO.serviceWith和ZIO.serviceWithZIO验证层组合
  • Akka:检查Actor层级和监督策略

Works Well With

适配技能

  • moai-lang-java - JVM interoperability, Spring Boot integration
  • moai-domain-backend - REST API, GraphQL, microservices patterns
  • moai-domain-database - Doobie, Slick, database patterns
  • moai-workflow-testing - ScalaTest, MUnit, property-based testing

  • moai-lang-java - JVM互操作性、Spring Boot集成
  • moai-domain-backend - REST API、GraphQL、微服务模式
  • moai-domain-database - Doobie、Slick、数据库模式
  • moai-workflow-testing - ScalaTest、MUnit、属性化测试

Additional Resources

额外资源

For comprehensive reference materials:
  • reference.md - Complete Scala 3.4 coverage, Context7 mappings, performance
  • examples.md - Production-ready code: Http4s, Akka, Spark patterns

Last Updated: 2026-01-11 Status: Production Ready (v2.1.0)
如需完整参考资料:
  • reference.md - 完整Scala 3.4覆盖、Context7映射、性能优化
  • examples.md - 生产级代码示例:Http4s、Akka、Spark模式

最后更新:2026-01-11 状态:生产就绪(v2.1.0)