142-java-functional-programming

仓库创建 2025年2月9日最近提交 3 天前SkillHot 收录 21 天前
▸ 精选理由

面向设计实践与 API 改良,适合迁移到更函数化风格

这个 Skill 做什么

在 Java 中应用函数式编程原则,提升不可变性与表达力

把函数式编程的思想引入 Java 代码:强调不可变对象/Record、纯函数、lambda、Stream 管道、Optional、函数组合和受控继承(sealed)等实践,提升可读性和并发安全性。需要把代码重构得更声明式、可测试或减少副作用时使用。特别之处是覆盖从语言特性到设计模式的一整套实用技巧,不只是做表面改写。

▸ 展开 SKILL.md 英文原文

Use when you need to apply functional programming principles in Java — including writing immutable objects and Records, pure functions, functional interfaces, lambda expressions, Stream API pipelines, Optional for null safety, function composition, higher-order functions, pattern matching for instanceof and switch, sealed classes/interfaces for controlled hierarchies, Stream Gatherers for custom operations, currying/partial application, effect boundary separation, and concurrent-safe functional patterns. This should trigger for requests such as Improve the code with Functional Programming; Apply Functional Programming; Refactor the code with Functional Programming. Part of cursor-rules-java project

开发编程Java函数式编程不可变通用
423
Stars
89
Forks
40
仓库内 Skill
+9
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/142-java-functional-programming/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/142-java-functional-programming/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Java Functional Programming rules

Identify and apply functional programming principles in Java to improve immutability, expressiveness, and maintainability.

**What is covered in this Skill?**

- Immutable objects and Records (JEP 395)
- Pure functions free of side effects
- Functional interfaces: `Function`, `Predicate`, `Consumer`, `Supplier`, custom `@FunctionalInterface`
- Lambda expressions and method references
- Stream API: filter/map/reduce pipelines, parallel streams, `toUnmodifiable*` collectors
- `Optional` idiomatic usage: `map`/`flatMap`/`filter`/`orElse*` over `isPresent()`+`get()`
- Function composition: `andThen`/`compose`
- Higher-order functions: memoization, currying, p
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有