Unary function arity

OSCC · JavaScript, Function · Oct 22, 2020

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

  • Call the provided function, fn, with just the first argument supplied.
const unary = fn => val => fn(val);
['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10]

Recommended snippets

  • Function arity

    JavaScript, Function

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

  • Binary function arity

    JavaScript, Function

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

  • Bind object method

    JavaScript, Function

    Creates a function that invokes the method at a given key of an object, optionally prepending any additional supplied parameters to the arguments.