Call or return
Calls the argument if it's a function, otherwise returns it.
const callOrReturn = (fn, ...args) => typeof fn === 'function' ? fn(...args) : fn;
callOrReturn(x => x + 1, 1); // 2 callOrReturn(1, 1); // 1
Written by Angelos Chalaris
If you want to keep in touch, follow me on GitHub or Twitter.