Skip to content
Agentmart
Submit a tool

migrate-layered-function-design

Use when writing or refactoring F# functions whose body mixes abstraction levels, construction details, or implicit invariants that should be isolated behind…

Skill by lamg

IndexedApache-2.0★ 13
Write a review

Chalk Labs

Need help deploying migrate-layered-function-design?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/lamg-migrate-layered-function-design

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when writing or refactoring F# functions whose body mixes abstraction levels, construction details, or implicit invariants that should be isolated behind named steps.

Use cases: design, writing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/migrate-layered-function-design

What's inside

Skill name
migrate-layered-function-design
Description
Use when writing or refactoring F# functions whose body mixes abstraction levels, construction details, or implicit invariants that should be isolated behind named steps.
License
Apache-2.0
Instructions
127 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Migrate Layered Function Design

## Core principle

A function should be readable as one coherent level of reasoning.

When a function interleaves high-level decisions with lower-level construction details, the reader must understand two programs at once: the algorithm being expressed and the subordinate mechanisms used to express it. Refactor so the outer function states the main argument, while helpers discharge lower-level obligations.

This is not extraction for line count. It is abstraction as a correctness tool: each named helper should capture a meaningful value, decision, invariant, or transformation.

## When to apply

- Apply this when a function body mixes orchestration with parsing, SQL construction, reflection, code generation, validation, or other lower-level mechanics.
- Apply this when several bindings exist only to construct one higher-level value used later.
- Apply this when earlier code establishes an invariant that later code silently relies on.
- Apply this when understanding the main function requires mentally executing an unrelated lower-level algorithm.

## Design rule

- Keep the outer function at the highest useful level of abstraction.
- Move lower-level detail into helpers named for what they establish, not how they happen to compute it.
- Prefer the smallest extraction that makes the reasoning boundary clear.
- Do not hide essential control flow, resource lifetime, transactions, or error handling behind vague helper names.
- Do not introduce public API surface for a local reasoning problem.

## Helper quality

A good helper name lets the caller read as if the result had already been specified.

Good helper names describe:

- a domain value: `buildTablePlan`, `inferPrimaryKey`, `generateViewQueries`
- a decision: `requiresDrainReplay`, `canUseFastPath`
- an invariant: `ensureCompatibleSchema`, `validateMigrationOrder`
- a transformation: `normalizeColumnName`, `quoteSqlIdentifier`

Weak helper names merely repeat mechanics:

- `processItems`
- `handleData`
- `doValidation`
- `getStuff`
- `buildResult`

## Refactoring procedure

1. Identify the result the function is trying to establish.
2. Identify bindings that belong to a lower-level concern than that result.
3. Group the lower-level bindings by the value, decision, or invariant they produce.
4. Extract each group only if its name improves the caller.
5. Keep the helper local if it is only part of this function's proof.
6. Move the helper to a private or internal module only when reuse or testing justifies it.
7. Re-read the outer function and check that it now describes the main reasoning path without forcing the reader into implementation detail.

## Example

Avoid mixing the construction of `V` with the lower-level construction of `E` values:

```fsharp
let f () =
    let value0: V = getValue 0
    let exp0: E = getExp 0
    let exp1: E = getExp 1
    let value1: V = joinExps exp0 exp1
    value0, value1
```

Prefer naming the lower-level obligation:

```fsharp
let private getValueFromExps () =
    let exp0: E = getExp 0
    let exp1: E = getExp 1
    joinExps exp0 exp1

let f () =
    let value0: V = getValue 0
    let value1: V = getValueFromExps ()
    value0, value1
```

Here `f` speaks in terms of `V`, the value level relevant to its result. The `E` construction is a subordinate concern and belongs behind a name.

If the helper is only meaningful inside `f`, prefer a local helper:

```fsharp
let f () =
    let getValueFromExps () =
        let exp0: E = getExp 0
        let exp1: E = getExp 1
        joinExps exp0 exp1

    let value0: V = getValue 0
    let value1: V = getValueFromExps ()
    value0, value1
```

## When not to apply

- Do not extract a helper just because a function is long.
- Do not extract a one-line binding unless the name states a real domain concept.
- Do not split code when the caller still needs to know every detail inside the helper.
- Do not create a helper whose name is less precise than the code it hides.
- Do not obscure sequencing, mutation, disposal, transactions, retries, or error propagation.
- Do not add backward-compatibility wrappers unless there is a concrete persisted, public, or external consumer.

## Relation to module layering

This skill is about reasoning inside functions.

If the same lower-level helpers accumulate across a file and form a reusable responsibility layer, also apply `migrate-layered-module-splitting`.

## Checklist

- Does the outer function now read at one abstraction level?
- Does each extracted helper have a name stronger than its implementation?
- Does each helper establish a value, decision, invariant, or transformation?
- Is the helper placed at the narrowest useful scope?
- Are lower-level details hidden without hiding essential behavior?

From lamg/migrate, Apache-2.0.

Signals

Stars
13
Forks
0
Open issues
0
Last commit (this folder)
Apr 30, 2026 (6 months ago)
Last release
Apr 1, 2026 (7 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from lamg

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get migrate-layered-function-design running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying migrate-layered-function-design?

CallGet help
Cite this page

migrate-layered-function-design skill. Agent Mart. https://agentmart.dev/skills/lamg-migrate-layered-function-design (last updated 2026-10-24)