142-java-functional-programming
面向设计实践与 API 改良,适合迁移到更函数化风格
在 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
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/142-java-functional-programming/SKILL.mdcurl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/142-java-functional-programming/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