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

A certain portion of programmers seems convinced that currying offers a huge amount of power, and we just haven't unlocked it yet. But I don't think I understand why they feel that way.



It's just a different way of structuring.

api = new Api('http://my.cool.api')

api.get('/it')

api.post('/it')

// connect = rootUrl => method => endpoint

api = connect('http://my.cool.api')

get = api('GET')

post = api('POST')

get('/it')

post('/it')


It mostly allows you to write extremely short code.

E.g. `sumList = reduce(sum)`

It has a variety of drawbacks though, like being harder to inspect at runtime, and arguably harder to read.


Yup, couldn't agree more and that's exactly one of the concerns I'm trying to address in the blog post ("All in all, the resulting effect in my exprience is that currying makes writing code far more pleasurable, but often makes reading code somewhat confusing."). I think the combination of named parameters actually makes it more readable.


it offers some elegance, here's a timeout function blogpost.

http://hyegar.com/2016/03/22/simple-timeouts/

In it the timeout function only takes one arg for its timeout wrapped function, so how do we use functions with more than 1 arg? Via currying


Curried: map (f . fst)

Uncurried: \xs -> map (\x -> f (fst x)) xs

Now comparing this to js would just be unfair (edit: ES6 lambdas are probably ok).




Applications are open for YC Winter 2019

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

Search: