froebel
froebel copied to clipboard
Utility Request: Unary
It would be great to have a unary
utility. Like this in plain JS but not sure how to implement it in TS:
const unary = (f) => {
return f.length === 1 ? f : (args) => f(args)
}
That way we could do things like:
['1', '2', '3'].map(unary(parseInt))
Example this discussion/explanation about why the unary utility is useful.
My apologies if this already exists in here under a different name. This is a fantastic library! 👏
Thanks for the suggestion. I think a unary
function would make a great addition to the library!
I'll do some research on what common naming conventions for this are in other libraries and languages. Maybe it's also worthwhile to add a more generic function that changes the number of arguments to any arbitrary number and have unary
be a special case of that function.
Will add the utility some time in the coming days. Unless, that is, you want to have a stab at adding it yourself.
Thanks that would be great! I've tried to do a typed version of the js example above but I'm not able to get it working, sorry. Looking forward to seeing how you implement it and learning from your TypeScript skills! 🙌