how to use the over function from the lodash library in typescript

To use the over function from the Lodash library in TypeScript, you first need to install it via npm:

index.ts
npm install lodash
19 chars
2 lines

You then import the function and define the functions you want to "over" (apply the function to):

index.ts
import { over } from 'lodash';

const getSum = (a: number, b: number) => a + b;
const getProduct = (a: number, b: number) => a * b;

const overFunc = over([getSum, getProduct]);

console.log(overFunc(2, 3)); // [5, 6]
218 chars
9 lines

In this example, the over function is applied to getSum and getProduct, which are both functions that take two arguments (a and b) and return a value. The over function returns a new function that takes the same arguments as the original functions, and applies each function to the arguments given. In this case, when overFunc is called with arguments 2 and 3, it applies getSum(2, 3) and getProduct(2, 3), and returns the array [5, 6].

gistlibby LogSnag