Centralize configure-able factory classes

This commit is contained in:
2022-09-26 11:34:23 -05:00
parent 5557aae543
commit c0595f3ef9
23 changed files with 262 additions and 682 deletions

View File

@@ -0,0 +1,27 @@
/**
* 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
}