Usage
1. Basic Function Wrapping
1const add = (a, b) => a + b;2const loggedAdd = FunctionWrapper.log(add);4console.log(loggedAdd(2, 3));56
1const multiply = (a, b) => a * b;3const enhancedFn = FunctionWrapper.chain(multiply)4 .log()5 .time()6 .memo()7 .value();9console.log(enhancedFn(5, 6));
3. Debounce / Throttle
1const save = (data) => console.log('Saved:', data);2const debouncedSave = FunctionWrapper.debounce(save, 500);3const throttledSave = FunctionWrapper.throttle(save, 1000);
4. Retry with Delay
1const unstable = () => {2 if (Math.random() < 0.7) throw new Error('Fail');3 return 'Success';4};6const reliable = FunctionWrapper.retry(unstable, 5, 100);7reliable().then(console.log).catch(console.error);
5. Undoable Functions
1let counter = 0;2const increment = () => ++counter;3const decrement = () => --counter;5const undoableIncrement = FunctionWrapper.undoable(increment, decrement);6undoableIncrement(); 7undoableIncrement.undo();
6. Monitoring and Stats
1const slowFn = (x) => new Promise(res => setTimeout(() => res(x * 2), 100));2const profiled = FunctionWrapper.stats(slowFn);4profiled(2).then(() => {5 console.log(profiled.stats); 6});