Effect Path API: Navigating Computational Territory
"A map is not the territory it represents, but, if correct, it has a similar structure to the territory, which accounts for its usefulness."
— Alfred Korzybski, Science and Sanity
Every Java application navigates territory that doesn't appear on any class diagram: the landscape of what might go wrong. A database connection that refuses to connect. A user ID that points to nobody. A file that was there yesterday. A validation rule that nobody told you about.
Traditional Java handles this territory with a patchwork of approaches: nulls here, exceptions there, Optional when someone remembered, raw booleans when they didn't. Each approach speaks a different dialect. None compose cleanly with the others.
The Effect Path API provides a unified map for this territory.
Rather than learning separate idioms for absence (Optional), failure (try-catch), typed errors (Either), and deferred effects (CompletableFuture), you work with Path types: thin, composable wrappers that share a common vocabulary. The same map, via, and recover operations work regardless of what kind of effect you're handling. The underlying complexity remains (it must), but the Path contains it.
If you've used the Focus DSL from the optics chapters, the patterns will feel familiar. Where FocusPath navigates through data structures, EffectPath navigates through computational effects. Both use via for composition. Both provide fluent, chainable operations. The territory differs; the cartography rhymes. And when you need to cross between territories—extracting structured data into effect pipelines, or drilling into effect results with optics—the bridge API connects both worlds seamlessly.
-
Effect Path Overview – The problem that Path types solve, the railway model of effect composition, and your first taste of the API.
-
Capability Interfaces – The hierarchy of powers that Path types possess: Composable, Combinable, Chainable, Recoverable, Effectful, and Accumulating. What each unlocks, and why the layering matters.
-
Path Types – The full arsenal:
MaybePath,EitherPath,TryPath,IOPath,ValidationPath,TrampolinePath,FreePath,FreeApPath, and more. When to reach for each, and what distinguishes them. -
Composition Patterns – Sequential chains, independent combination, parallel execution, debugging with
peek, and the art of mixing composition styles. -
Type Conversions – Moving between Path types as your needs change. The bridges between
MaybeandEither, betweenTryandValidation, and the rules that govern safe passage. -
Focus-Effect Integration – Bridging optics and effects. Converting FocusPath to EffectPath for validation pipelines, using
focus()to navigate within effect contexts, and patterns that combine both domains. -
Patterns and Recipes – Real-world patterns distilled from production code: validation pipelines, service orchestration, fallback chains, resilience with retry, and the pitfalls that await the unwary.
-
Advanced Effects – Reader, State, and Writer paths for environment access, stateful computation, and logging accumulation.
-
Advanced Topics – Stack-safe recursion, DSL building with Free structures, resource management, parallel execution, and resilience patterns.
Core Patterns:
- BasicPathExample.java - Creating and transforming paths
- ChainedComputationsExample.java - Fluent chaining patterns
- ErrorHandlingExample.java - Recovery and error handling
- ServiceLayerExample.java - Real-world service patterns
Advanced Effects:
- AdvancedEffectsExample.java - Reader, State, and Writer paths
- LazyPathExample.java - Deferred, memoised computations
- CompletableFuturePathExample.java - Async operations
- CollectionPathsExample.java - List and Stream effects
Stack-Safety, Resources, Parallelism & Resilience:
- TrampolinePathExample.java - Stack-safe recursion
- FreePathExample.java - DSL building and interpretation
- ResourceManagementExample.java - bracket, withResource, guarantee
- ParallelExecutionExample.java - parZipWith, parSequence, race
- ResilienceExample.java - RetryPolicy and backoff patterns
Chapter Contents
- Effect Path Overview - The problem, the model, the first steps
- Capability Interfaces - The interface hierarchy powering composition
- Path Types - Detailed coverage of each Path type
- Composition Patterns - Chaining, combining, parallel execution, and debugging
- Type Conversions - Moving between different Path types
- Focus-Effect Integration - Bridging optics and effects
- Patterns and Recipes - Real-world patterns, resilience, and hard-won wisdom
- Advanced Effects - Reader, State, and Writer patterns
- Advanced Topics - Stack-safety, DSLs, resources, parallelism, resilience
Next: Effect Path Overview