You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
574 B
28 lines
574 B
2 years ago
|
/**
|
||
|
* Apply a series of operators to a value, returning the original value.
|
||
|
*
|
||
|
* Helpful for values/methods that don't support chaining.
|
||
|
*
|
||
|
* @example
|
||
|
* ```ts
|
||
|
* const inOneHour = () => tap(new Date, d => d.setMinutes(d.getMinutes() + 60))
|
||
|
* ```
|
||
|
*
|
||
|
* This is equivalent to:
|
||
|
*
|
||
|
* ```ts
|
||
|
* const inOneHour = () => {
|
||
|
* const d = new Date
|
||
|
* d.setMinutes(d.getMinutes() + 60)
|
||
|
* return d
|
||
|
* }
|
||
|
* ```
|
||
|
*
|
||
|
* @param value
|
||
|
* @param ops
|
||
|
*/
|
||
|
export function tap<T>(value: T, ...ops: ((t: T) => unknown)[]): T {
|
||
|
ops.forEach(op => op(value))
|
||
|
return value
|
||
|
}
|