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

To use the rearg function from the Lodash library in TypeScript, you will need to install the Lodash library into your project by running the following command:

index.ts
npm install --save lodash
26 chars
2 lines

Then, in your TypeScript file, you can import rearg from the Lodash library:

index.ts
import { rearg } from 'lodash';
32 chars
2 lines

Here is an example of how you can use rearg:

index.ts
function foo(a: number, b: number, c: number) {
  console.log(a, b, c);
}

const newFoo = rearg(foo, [0, 2, 1]);

newFoo(1, 2, 3); // Logs "1 3 2"
147 chars
8 lines

In this example, the rearg function is used to create a new function (newFoo) with the order of the arguments rearranged. The foo function takes 3 arguments, and the rearg function is passed an array indicating the new order of the arguments. The new function, newFoo, can then be called with the rearranged argument order as shown.

gistlibby LogSnag