Skip to content

feat(fp): add function utilities (pipe, flow, identity, constant, flip, tupled, untupled) - #433

Open
martyy-code wants to merge 1 commit into
stagingfrom
function/pipe-and-friends
Open

feat(fp): add function utilities (pipe, flow, identity, constant, flip, tupled, untupled)#433
martyy-code wants to merge 1 commit into
stagingfrom
function/pipe-and-friends

Conversation

@martyy-code

Copy link
Copy Markdown
Contributor

Summary

Delivers the seven function utilities that the documentation has been
promising since v1.0 (docs/internal/product/features/function-utilities.md)
and that the README quotes as ergonomic essentials:

  • pipe — left-to-right function composition with a starting value.
  • flow — left-to-right function composition that returns a function.
  • identity — the identity function.
  • constant — wraps a value into a function that ignores its argument.
  • flip — swaps the first two arguments of a binary function.
  • tupled / untupled — tuple ↔ positional adapters.

pipe and flow carry variadic overloads up to nine steps. Beyond
that the tail collapses to unknown and the caller is on their own.

Why this PR

The README and the docs both reference pipe as the canonical way to
compose the Result/Maybe pipeables. Before this PR, the JSDoc in
result/functions.ts and maybe/functions.ts literally wrote
pipe(value, map(fn), flatMap(chain)), but pipe did not exist.
A consumer copy-pasting the README example would get a TypeScript\nerror at import time. This PR closes the gap.

The pipeables shipped in PR #431 are now usable through pipe as the
documentation already advertises.

Public API

The seven exports are added to the public barrel under their bare
names. No collision with the existing pipeables (which are suffixed
with Maybe for the Maybe namespace).

Verification

  • pnpm --filter @deessejs/fp type-check — clean
  • pnpm --filter @deessejs/fp lint — clean
  • pnpm --filter @deessejs/fp test:run — 230 passed (was 202)
  • pnpm --filter @deessejs/fp test:coverage — 100% statements /
    branches / functions / lines, thresholds pinned at 100%

Changeset

minor — new public exports.

Plan

See docs/engineering/plans/function-utilities.md.

🤖 Generated with Claude Code

…p, tupled, untupled)

These are the seven exports that the documentation has been promising
since v1.0 (docs/internal/product/features/function-utilities.md) and
that the README quotes as ergonomic essentials. The pipeables shipped
in PR #431 (map, flatMap, ...) are now usable through pipe as the
JSDoc in result/functions.ts and maybe/functions.ts already documents.

`pipe` and `flow` carry variadic overloads up to nine steps. Beyond
that the tail collapses to `unknown` and the caller is on their own.

`tupled` and `untupled` are inverses. Tests assert both directions.

Coverage stays at 100% across statements, branches, functions, and
lines. Vitest thresholds remain pinned at 100% (set in PR #431).

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

File % Stmts % Branch % Funcs % Lines
Total 100.00% 100.00% 100.00% 100.00%
packages/fp/src/function/constant.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/flip.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/flow.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/identity.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/index.ts 0.00% n/a 0.00% 0.00%
packages/fp/src/function/pipe.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/tupled.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/function/untupled.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/maybe/constants.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/maybe/functions.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/maybe/index.ts 0.00% n/a 0.00% 0.00%
packages/fp/src/maybe/internal/none-impl.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/maybe/internal/some-impl.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/result/constants.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/result/functions.ts 100.00% n/a 100.00% 100.00%
packages/fp/src/result/index.ts 0.00% n/a 0.00% 0.00%
packages/fp/src/result/internal/err-impl.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/result/internal/ok-impl.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/unit/constants.ts 100.00% 100.00% 100.00% 100.00%
packages/fp/src/unit/index.ts 0.00% n/a 0.00% 0.00%

Per-file thresholds: 100% on statements / branches / functions / lines (ADR 0002). Files with no branches render n/a in the Branch column. The threshold gate is disabled in this PR and lands with the full method × variant test matrix in a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant