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
85
81%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
Identify and apply functional programming principles in Java to improve immutability, expressiveness, and maintainability.
What is covered in this Skill?
Function, Predicate, Consumer, Supplier, custom @FunctionalInterfacetoUnmodifiable* collectorsOptional idiomatic usage: map/flatMap/filter/orElse* over isPresent()+get()andThen/composeinstanceof and switch (Java 21)List.of(), Collectors.toUnmodifiableList()Scope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
Before applying any functional programming changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until the project compiles successfully. Verify that maven-compiler-plugin source/target supports the Java features being used.
./mvnw compile or mvn compile before applying any changes./mvnw clean verify or mvn clean verify after applying improvementsRun ./mvnw compile or mvn compile and stop immediately if compilation fails.
Verify maven-compiler-plugin source/target supports the functional features planned for adoption.
Read references/142-java-functional-programming.md and identify opportunities for immutability, pure functions, and functional composition.
Implement selected functional refactorings while keeping side effects at boundaries.
Run ./mvnw clean verify or mvn clean verify after applying improvements.
For detailed guidance, examples, and constraints, see references/142-java-functional-programming.md.
762cb86
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.