refactor: flatten nested call chains#26350

merged1
main
t3/flatten-nested-calls
opened4d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 4d ago

Many call sites nested plain function calls three or more levels deep, so you read them inside out. The most common case was Option.getOrNull(AsyncResult.value(x)), which hand-inlines what AsyncResult already provides. I found them with an AST scan of the repo (oxc-parser), looking for calls passed as another call's first argument at least three levels deep.

What changed:

  • Option.getOrElse(AsyncResult.value(x), f) becomes AsyncResult.getOrElse(x, f), and Option.getOrNull(AsyncResult.value(x)) becomes AsyncResult.getOrElse(x, () => null). Effect defines AsyncResult.getOrElse as exactly that composition, so behaviour is unchanged. 82 sites; the Option imports this left unused are removed.
  • About 40 chains that pass one value through several steps (removeLogged(storeName(refFor(…))), setError(message(squashAtomCommandFailure(result))), the theme colour solve, the MCP asset HTML rewrite, and others) now read top to bottom with pipe from effect/Function. Effect and Stream values use .pipe instead.
  • The six identical sortProviderInstanceEntries(applyProviderInstanceSettings(deriveProviderInstanceEntries(…))) chains now call one helper, providerInstanceEntriesFor. sortProviderInstanceEntries had no other callers, so it is now private.

Left as they were: chains where the inner calls only build one argument of a call that has other arguments too, such as provide(runSshCommand(targetFor(config), {…})) and anchorNewTurn(scopedThreadKey(scopeThreadRef(…)), messageId). Rewriting those as pipe would need a lambda for nearly every step.

vp run check:changed passes: format, lint, knip, typecheck of 32 packages, and 61 test files.

Model: Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code

Checks

1 failing · 24 successful · 13 skipped
Some checks failed

Failing1

785fae2

Added 1 commit

  • refactor: flatten nested call chains785fae2