es-toolkit/docs/reference/function/unary.md
D-Sketon ec1a55850c
Some checks failed
CI / codecov (push) Has been cancelled
Release / release (push) Has been cancelled
feat(ary/unary): implement ary/unary (#325)
* feat(ary/unary): implement ary/unary

* fix

---------

Co-authored-by: Sojin Park <raon0211@toss.im>
2024-08-04 23:23:00 +09:00

554 B

unary

Creates a function that accepts up to one argument, ignoring any additional arguments.

Signature

function unary<F extends (...args: any[]) => any>(func: F): (...args: any[]) => ReturnType<F>;

Parameters

  • func (F): The function to cap arguments for.

Returns

((...args: any[]) => ReturnType<F>): Returns the new capped function.

Examples

import { unary } from 'es-toolkit/function';

function fn(a, b, c) {
  console.log(arguments);
}

unary(fn)(1, 2, 3); // [Arguments] { '0': 1 }