Hacker News new | past | comments | ask | show | jobs | submit login

Currying makes it implicit, but it's the same thing.

    const one = curriedSum(1)
    one(2)
is the same as

    const one = sum.bind(null, 1)
    one(2)
with the exception that the latter is explicit and not as slow as `curriedSum`.

Both `sum` and `curriedSum` can be used the same way:

    curriedSum(1)(2)
    sum.bind(null, 1)(2)
or just:

    curriedSum(1, 2)
    sum(1, 2)
One of the advantages is that non-curried functions make the return value explicit. You can't implement `sum(...addends)` with currying because curried functions have a fixed number of parameters. Once past that, a call will not return a function anymore.

    sum.bind(null, 1).bind(null, 2).bind(null, 3).bind(null, 4) // Still not called
    curriedSum(1)(2)(3)(4) // Maybe it works, maybe undefined is not a function



They're technically correct. And if you gotta write on HN, you better get the terminology correct (and that derails threads into interesting tangents often) so my bad.

Gotta say currying seems to be useless in real world. No advantage whatsoever over partial application.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: