tap
tap<
K
,T
>(fn
:T
[K
]):Funcware
<MethodOf
<HasMethod
<K
>,K
>>
Defined in: ext/funcware/tap.ts:29
Creates funcware that taps into a method call, running a side-effect function after the original method.
Use cases:
- Logging, analytics, or debugging after method execution
- Triggering side effects without altering the original return value
- Composing additional behavior in functional pipelines
Type Parameters
Section titled “Type Parameters”Type Parameter | Description |
---|---|
K extends string | The method name |
T extends HasMethod <K > | The target type with the method |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
fn | T [K ] | The function to run after the original method |
Returns
Section titled “Returns”Funcware
<MethodOf
<HasMethod
<K
>, K
>>
Funcware that runs the side-effect function after the original method
Source
Section titled “Source”This function is useful for scenarios where you want to observe or react to method calls without changing their result, such as for logging, metrics, or triggering external effects.
export const tap = <K extends string, T extends HasMethod<K>>( fn: T[K] ): Funcware<MethodOf<HasMethod<K>, K>> => (inner) => (...params) => { const res = inner(...params); fn(...params); return res; };
Example
Section titled “Example”const logParams = (...params: any[]) => console.log('Called with:', ...params);const tapware = tap(logParams);const original = (x: number) => x * 2;const tapped = tapware(original);tapped(5); // Logs 'Called with: 5', returns 10