Coming from Arrow¶
If you're already using Arrow's parZip for parallel execution, KAP can complement or replace it for multi-phase orchestration. This guide shows the migration path.
KAP + Arrow: complementary, not competing¶
KAP's kap-arrow module uses Arrow's Either and NonEmptyList. You don't have to choose one or the other:
dependencies {
implementation("io.github.damian-rafael-lattenero:kap-core:2.3.0")
implementation("io.github.damian-rafael-lattenero:kap-arrow:2.3.0") // uses Arrow Core
}
Simple parallel: parZip → combine¶
Almost identical. KAP's combine is Arrow's parZip equivalent.
Type-safe ordering: parZip → kap + .with¶
Multi-phase: sequential parZip → flat chain¶
This is where KAP shines. Arrow requires separate parZip calls with intermediate variables:
// Phase 1
val (user, cart) = parZip(
{ fetchUser() }, { fetchCart() },
) { u, c -> Pair(u, c) }
// Phase 2 (barrier — just a suspend call)
val validated = validate(user, cart)
// Phase 3
val (shipping, tax) = parZip(
{ calcShipping() }, { calcTax() },
) { s, t -> Pair(s, t) }
val result = Result(user, cart, validated, shipping, tax)
Value-dependent phases: nested parZip → .andThen¶
Validation: zipOrAccumulate → zipV¶
Features KAP adds over Arrow¶
| Feature | Arrow | KAP |
|---|---|---|
| Visible phases | No | .then / .andThen |
| Compile-time arg order | No | Typed function chain |
| Max arity | 9 | 22 |
timeoutRace |
No | Parallel fallback, 2.6x faster |
raceQuorum |
No | N-of-M consensus |
.settled() |
No | Partial failure tolerance |
.memoizeOnSuccess() |
No | Cache only successes |
| Parallel validation | zipOrAccumulate |
zipV (parallel + arity 22) |