magnolia
800
Stars
—
Forks
0
Watchers
—
Open Issues
待补全
许可证
Scala
语言
—
创建时间
最近更新
项目能做什么
Magnolia 是一个用于 Scala 的类型类(Typeclass)自动派生工具。它解决了手动为复杂数据类型编写重复模板代码的痛点。核心功能是通过轻量级语法,为样例类(case classes)和枚举/密封特质(sealed traits)自动生成类型类实例,开箱即用支持递归数据结构且编译速度极快。
来源:AI 基于仓库事实生成
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)

[<img alt="GitHub Workflow" src="https://img.shields.io/github/actions/workflow/status/softwaremill/magnolia/ci.yml?branch=scala3&style=for-the-badge" height="24">](https://github.com/softwaremill/magnolia/actions)
[<img src="https://img.shields.io/badge/Discourse-ask%20question-blue?style=for-the-badge" height="24">](https://softwaremill.community/c/magnolia)
[<img src="https://index.scala-lang.org/softwaremill/magnolia/magnolia/latest-by-scala-version.svg?color=2465cd&style=for-the-badge" height="24">](https://index.scala-lang.org/softwaremill/magnolia/magnolia)
# Magnolia
__Magnolia__ is a generic macro for automatic materialization of typeclasses for datatypes composed from product types (e.g. case classes) and coproduct types (e.g. enums). It supports recursively-defined datatypes out-of-the-box, and incurs no significant time-penalty during compilation.
## Features
- derives typeclasses for case classes, case objects and sealed traits
- offers a lightweight syntax for writing derivations without needing to understand complex parts of Scala
- builds upon Scala 3's built-in generic derivation
- works with recursive and mutually-recursive definitions
- supports parameterized ADTs (GADTs), including those in recursive types
- supports typeclasses whose generic type parameter is used in either covariant and contravariant positions
## Getting Started
Given an ADT such as,
```scala
enum Tree[+T] derives Print:
case Branch(left: Tree[T], right: Tree[T])
case Leaf(value: T)
```
and provided a given instance of `Print[Int]` is in scope, and a Magnolia derivation for the `Print` typeclass
has been provided, we can automatically derive given typeclass instances of `Print[Tree[Int]]` on-demand, like
so,
```scala
Tree.Branch(Tree.Branch(Tree.Leaf(1), Tree.Leaf(2)), Tree.Leaf(3)).print
```
Typeclass authors may provide Magnolia derivations in the typeclass's companion object, but it is easy to create
your own.
Creating a generic derivation with Magnolia requires implementing two methods on `magnolia1.Derivation`:
* `join()` : create typeclasses for case classes ('product types')
* `split()` : create typeclasses for sealed-traits/enums ('sum types')
### Example derivations
There are many examples in the [`examples`](examples/src/main/scala/magnolia1/examples) sub-project.
The definition of a `Print` typeclass with generic derivation might look like this
(note we're using the [Lambda syntax for Single Abstract Method types](https://www.scala-lang.org/news/2.12.0/#lambda-syntax-for-sam-types)
to instantiate the `Print` instances in `join` & `split` - that's possible because
`Print` has only a single abstract method, `print`):
```scala
import magnolia1.*
trait Print[T] {
extension (x: T) def print: String
}
object Print extends AutoDerivation[Print]:
def join[T](ctx: CaseClass[Print, T]): Print[T] = value =>
ctx.params.map { param =>
param.typec
阅读完整原文
项目深度分析 AI 生成
Scala 2 到 Scala 3 宏与类型推导迁移顾问服务
| 产品构想 | 利用对 Magnolia 及其编译期机制的深度理解,为受困于 Scala 3 升级(特别是宏与类型推导破坏性变更)的企业提供定制化代码迁移与性能优化服务。 |
| 核心功能 | 宏代码审计、Magnolia 派生逻辑跨版本平滑升级、编译期耗时诊断与调优报告。 |
| 目标用户 | 维护大型遗留 Scala 代码库的中大型企业、金融科技公司。 |
| 难度/周期 | 高 · 2-3 个月 · 成本:人力成本(需精通 Scala 3 元编程特性的高级工程师) |
| 收费模式 | 按人天或项目整体交付收取的专业技术咨询费用 |
| 竞争风险 | 目标客户群体较窄且 Scala 市场规模有限;各家企业定制宏差异极大导致难以标准化。 |
| 依据 | AI推测 |
企业级高性能序列化与协议编解码生成框架
| 产品构想 | 基于 Magnolia 封装上层的企业级数据编解码套件,针对金融/风控高吞吐场景优化,提供 Protobuf/Avro/JSON 极速派生能力与企业审计功能。 |
| 核心功能 | 开箱即用的类型类定义、零额外开销的高速编解码、数据脱敏与 schema 演进合规检查插件。 |
| 目标用户 | 数据密集型 Scala 平台架构师、微服务中间件开发团队。 |
| 难度/周期 | 中等 · 1-3 个月 · 成本:开发与基准性能测试基础设施成本 |
| 收费模式 | 双重许可(Dual-License)或高级企业扩展包收费(如企业 Schema Registry 集成) |
| 竞争风险 | 开源竞品(如 circe、zio-json、borer)已自带完善的派生支持,重复造轮子接受度低。 |
| 依据 | 尚需验证的假设 |
Scala 元编程与高性能工程企业内训课程
| 产品构想 | 开发针对 Magnolia 及 Scala 3 泛型派生、宏系统、编译器插件的高阶实战培训体系,帮助团队突破技术瓶颈。 |
| 核心功能 | 体系化元编程课程、Magnolia 内部机制拆解、真实大型项目实战练习、课后答疑。 |
| 目标用户 | 正在向 Scala 3 转型的研发团队主管、中高级 Scala 工程师。 |
| 难度/周期 | 低 · 2-4 周 · 成本:课程内容制作与讲师时间成本 |
| 收费模式 | B2B 团队内训打包收费、线上付费专业专栏 |
| 竞争风险 | Scala 开发者基数持续受限,购买高阶内训的预算审批周期长。 |
| 依据 | 已验证事实 |
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
相似项目数据正在完善中,暂不展示(避免误导)
项目优势与风险
| 技术成熟度 | 创建时间待补全,最近推送 ,发布过 72 个 Release |
| 社区活跃 | Star 800 / Fork 0 / Issue 0(数据支持,可自行核实) |
| 许可证 | 未检测到(需人工确认) |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
此项目未提供 Docker 镜像,安装步骤以原仓库 README 为准(涉及依赖安装与环境配置,对新手门槛较高)。