21 lines
608 B
JavaScript
21 lines
608 B
JavaScript
//#region src/fp/math/multiply.ts
|
|
/**
|
|
* Creates a function that multiplies its input by `multiplicand`. Use it with
|
|
* {@link pipe}, or as the callback of a function such as {@link map}.
|
|
*
|
|
* @param multiplicand - The number to multiply the input by.
|
|
* @returns A function that maps a `number` to `value * multiplicand`.
|
|
*
|
|
* @example
|
|
* import { pipe, map, multiply } from 'es-toolkit/fp';
|
|
*
|
|
* pipe(3, multiply(2)); // => 6
|
|
* pipe([1, 2, 3], map(multiply(3))); // => [3, 6, 9]
|
|
*/
|
|
function multiply(multiplicand) {
|
|
return function(value) {
|
|
return value * multiplicand;
|
|
};
|
|
}
|
|
//#endregion
|
|
export { multiply };
|