Files
30-seconds-of-code/snippets/unary.md
2023-04-28 22:29:23 +03:00

20 lines
407 B
Markdown

---
title: Unary function arity
type: snippet
tags: [function]
cover: flower-portrait-2
dateModified: 2020-10-22T20:24:44+03:00
---
Creates a function that accepts up to one argument, ignoring any additional arguments.
- Call the provided function, `fn`, with just the first argument supplied.
```js
const unary = fn => val => fn(val);
```
```js
['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10]
```