30秒学会 JavaScript 片段 · 2019年7月7日

30秒学会 JavaScript 片段 – unary

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

Call the provided function, fn, with just the first argument given.

代码片段

const unary = fn => val => fn(val);

使用样例

['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10]