when
Returns a function that applies a transform only when a predicate passes, otherwise returns the value unchanged.
Usage
when<T>(predicate: (value: T) => boolean, fn: (value: T) => T)
Returns a function that applies a transform only when a predicate passes, otherwise returns the value unchanged.
Parameters
predicate(value: T) => booleanrequired
the condition used to select behavior.
fn(value: T) => Trequired
the transformation to apply when predicate returns true.
Returns
a function that transforms values only when predicate returns true.