Repository navigation
feat(function): add once run-at-most-once wrapper - #134
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
onceat a newwellcrafted/functionsubpath.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../functionis a new single-concept module alongsidebrand,json, andtesting: wired into theexportsmap 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.