functional-programming

Analyze and refactor PHP and TypeScript code for functional programming principles.

Updated Jun 19, 2023
One-click install
npx skills add https://github.com/JeroenJochems/modelwise --skill functional-programming-jeroenjochems
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: functional-programming
Source: https://github.com/JeroenJochems/modelwise/tree/main/.claude/skills/functional-programming
Command: npx skills add https://github.com/JeroenJochems/modelwise --skill functional-programming-jeroenjochems

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps you write more reliable, testable, and maintainable code by applying functional programming principles, reducing bugs caused by mutable state and side effects.

Core Features & Use Cases

  • Purity Enforcement: Identifies and guides the refactoring of impure functions that rely on or modify external state.
  • Immutability Guidance: Promotes the use of immutable data structures to prevent race conditions and simplify reasoning about state.
  • Side Effect Management: Helps isolate I/O and other side effects to the boundaries of your system, making core logic predictable.
  • Use Case: Refactor a complex order processing function that mixes business logic with database writes and external API calls into a pure core function and an imperative shell that handles the side effects.

Quick Start

Analyze the provided code snippet for functional programming violations.

Frequently Asked Questions about functional-programming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor imperative code to isolate side effects and improve purity?

To isolate side effects and improve purity, you refactor code by extracting business logic into pure functions and moving I/O operations to the boundaries of your system. This creates a predictable pure core and an imperative shell for side-effect management.

What is the best way to enforce immutability and prevent race conditions in TypeScript or PHP?

The best way to enforce immutability and prevent race conditions in TypeScript or PHP is to refactor mutable state into immutable data structures. This simplifies reasoning about state and removes unexpected mutations, making the code more robust and testable.

Why does mixing business logic with database writes cause bugs in my code?

Mixing business logic with database writes causes bugs because impure functions rely on and modify external state, creating unpredictable side effects. Isolating these side effects to the system boundaries makes the core logic predictable and reduces state-related bugs.

Can I use functional programming principles to refactor complex order processing functions?

Yes, you can refactor complex order processing functions by applying functional programming principles. This separates the mixed business logic and external API calls into a pure core function and an imperative shell that handles the side effects, improving overall code quality.

When should I not use functional programming refactoring on my existing codebase?

You should not use functional programming refactoring when your codebase heavily relies on mutable state and imperative loops that cannot be isolated, or when isolating side effects to the boundaries is architecturally unfeasible without a complete system rewrite.