Some of the benefits that you mention I think are more related with pure functions than currying itself. Though falsey values like null and undefined can still be a problem, if you pass undefined to getApi you probably won't get what you want.
I think currying is really helpful when you make heavy use of higher order functions. Using your example, you could take it even further with a couple of helper functions.
When writting imperative code currying is rarely used or needed. But the good thing about javascript is that you don't have to curry functions in order to take advantage of partial application, Function.bind can be quite helpful sometimes. You could write getApi like you would a normal function and still be able to create those specialized functions.
Thanks for sharing that! I've never used Function.bind and you've provided a really awesome use case for it. And I think I'm going to re-use that implementation for the curried function in another project.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Some of the benefits that you mention I think are more related with pure functions than currying itself. Though falsey values like null and undefined can still be a problem, if you pass
undefined
togetApi
you probably won't get what you want.I think currying is really helpful when you make heavy use of higher order functions. Using your example, you could take it even further with a couple of helper functions.
When writting imperative code currying is rarely used or needed. But the good thing about javascript is that you don't have to curry functions in order to take advantage of partial application,
Function.bind
can be quite helpful sometimes. You could writegetApi
like you would a normal function and still be able to create those specialized functions.Thanks for sharing that! I've never used
Function.bind
and you've provided a really awesome use case for it. And I think I'm going to re-use that implementation for the curried function in another project.