Skip to content

feat(function): add once run-at-most-once wrapper - #134

Merged
braden-w merged 1 commit into
mainfrom
braden-w/once-function
Jun 26, 2026
Merged

braden-w merged 1 commit into
mainfrom
braden-w/once-function

Conversation

@braden-w

Copy link
Copy Markdown
Collaborator

Adds once at a new wellcrafted/function subpath. once(fn) runs the wrapped function at most once: the first call invokes it and caches the result; every later call returns that cached result and ignores any arguments passed after the first.

It is a generic, dependency-free combinator, useful for idempotent disposal (a [Symbol.dispose] reachable from more than one teardown path) and lazy one-time initialization. The subpath is additive, so no existing import changes.

./function is a new single-concept module alongside brand, json, and testing: wired into the exports map and the tsdown entry list, and named with room for future combinators (memoize, debounce).

Carries a minor changeset; the version bump and CHANGELOG entry are left to the release flow.

Add a new wellcrafted/function subpath whose first export, once(fn), runs
the wrapped function at most once: the first call invokes it and caches the
result, and every later call returns that cached result while ignoring any
arguments passed after the first.

This is a generic, dependency-free combinator that previously lived
mis-homed in a heavy CRDT package; consumers can now reach it without that
dependency. The subpath is additive, so no existing import changes.
@braden-w
braden-w merged commit c144356 into main Jun 26, 2026
1 check passed
@braden-w
braden-w deleted the braden-w/once-function branch June 26, 2026 19:43
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