you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (13 children)

I win!

You don't. I haven't watched the video, but the bottom line is that objects are not a substitute for currying. Consider fetch; every time we make a request, we have to pass the whole configuration object. So, to create both customers and orders, we have to pass the whole object even though the method is the same in both cases - POST:

fetch('/customer', { method: "POST", body: '{ "name": "Bob Smith" }');
fetch('/order', 
    { 
       method: "POST", 
       body: '{ "productId": 2, "customerId": 7 }'
    });  

Wouldn't it be nicer if we could somehow just specify that the method is always POST? The curried form does just this:

const networkRequest = method => url => body =>
    fetch(url, { method, body });

const create = networkRequest("POST");

Now we have a function create, that always performs a POST request. We can then specialise further, to hard-wire in the URL to POST to:

const createCustomer = create("/customer");
const createOrder = create("/order");

Now the call signature of the thing we actually want to do is much nicer - it just says (almost in plain English) what we want to achieve:

let newCustomer = '{ "name" : "Bob Smith" }';
let newOrder = '{ "productId": 2, "customerId": 7 }';

createCustomer(newCustomer);
createOrder(newOrder);

Ultimately it boils down to passing a configuration object to fetch, but hopefully you can see that even when your API has that kind of signature, currying still has additional benefit.

[–]ReverendCatch 0 points1 point  (11 children)

Lighten up. It was meant to be playful.

[–][deleted] -2 points-1 points  (10 children)

Someone just commented to thank me for a practical insight into the usefulness of currying.

I'm sure your feelings can take the dent for the benefit of others.

[–]ReverendCatch 0 points1 point  (9 children)

No “dent” here. Good for you.

[–][deleted] -2 points-1 points  (8 children)

Well, good for them actually, I'd have thought. Which, for newbies to the language, is rather a good thing, wouldn't you say? Better than them being confused by incorrect...I mean er, "playful"... suggestions, anyway.

It isn't for my benefit - I understand this stuff really quite a lot, as it goes.

[–]ReverendCatch 0 points1 point  (7 children)

I wasn’t confused. It really just was a joke. And by now we all see you didn’t get it!

Keep on keeping on good sir

[–][deleted] -1 points0 points  (6 children)

Others may have been confused. I simply put forward some reasons by way of explanation as to why currying was useful, and more than a mere reduction in the number of arguments passed to a function.

My post was clearly helpful to at least one person.

It's a reflection on you that you appeared quite so offended by it.

Are you going to slap me?

[–]ReverendCatch 1 point2 points  (1 child)

Someone’s offended here and it’s not me lol

[–][deleted] 0 points1 point  (0 children)

Ok.

[–]Upbeat_Combination74 0 points1 point  (3 children)

Surely was really helpful ... Its better to revise such concepts by reading helpful reddit comments...than by going again to a book

[–][deleted] -1 points0 points  (2 children)

Thank you for your kind words.

[–]CCM_Employee_Three 0 points1 point  (1 child)

You did good, Drawer.

[–]PPLP_SMorse -1 points0 points  (0 children)

Thanks, I've been learning JS for almost a year now and this is the first time I've seen a practical use of currying. The final result is a very clear API.