2024-08-04 17:23:00 +03:00
|
|
|
# ary
|
|
|
|
|
2024-08-25 15:57:59 +03:00
|
|
|
Creates a function that invokes func, with up to `n` arguments, ignoring any additional arguments.
|
2024-08-04 17:23:00 +03:00
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
2024-08-11 04:54:13 +03:00
|
|
|
function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F>;
|
2024-08-04 17:23:00 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
- `func` (`F`): The function to cap arguments for.
|
2024-08-31 08:45:00 +03:00
|
|
|
- `n` (`number`): The arity cap.
|
2024-08-04 17:23:00 +03:00
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
|
|
|
(`(...args: any[]) => ReturnType<F>`): Returns the new capped function.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import { ary } from 'es-toolkit/function';
|
|
|
|
|
2024-08-31 08:45:00 +03:00
|
|
|
function fn(a: number, b: number, c: number) {
|
|
|
|
return Array.from(arguments);
|
2024-08-04 17:23:00 +03:00
|
|
|
}
|
|
|
|
|
2024-08-31 08:45:20 +03:00
|
|
|
ary(fn, 0)(1, 2, 3); // []
|
|
|
|
ary(fn, 1)(1, 2, 3); // [1]
|
|
|
|
ary(fn, 2)(1, 2, 3); // [1, 2]
|
|
|
|
ary(fn, 3)(1, 2, 3); // [1, 2, 3]
|
2024-08-04 17:23:00 +03:00
|
|
|
```
|