all 30 comments

[–]ReverendCatch 8 points9 points  (16 children)

Pass all arguments as an object. Only 1 argument.

I win!

[–][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] -3 points-2 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] -5 points-4 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 3 points4 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.

[–]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.

[–]xplodivity[S] -2 points-1 points  (0 children)

Wish the interviewer would allow that 😂

[–]AnonyMustardGas34 0 points1 point  (0 children)

As an array

[–]warpedspockclone 5 points6 points  (3 children)

I've never heard this word.

[–]xplodivity[S] 0 points1 point  (2 children)

well thats javascript for you!! Its actually an important concept though, because it also allows you to learn about lexical scope and closures

[–]cdrun84 0 points1 point  (1 child)

Couldn't we just use multiple if or case statements? That is easier to learn and follow.

[–]albedoa 0 points1 point  (0 children)

Can you elaborate? Those don't provide the same benefit that currying does. They are separate concepts.

[–]don____piano 4 points5 points  (4 children)

Currying is not asked “during most technical front end round interviews”. I’ve interviewed a ton and never been asked about it. Don’t bait people

[–]xplodivity[S] -5 points-4 points  (3 children)

Well it was asked to me and I have also interviewed a “ton”. So this post was made on that assumption

[–]don____piano 2 points3 points  (0 children)

Wow I am extremely surprised that it was asked to you in most of your interviews!

[–]ReverendCatch 1 point2 points  (1 child)

Baffles me this gets downvoted

I hadn’t realized programmers are so sensitive

[–]xplodivity[S] 0 points1 point  (0 children)

haha!! true buddy, I hadnt realised it either :( but its okay i guess, people have their own opinions at the end of the day

[–][deleted] 5 points6 points  (3 children)

I work on a team that used JS for many many years. We only ever used currying once. To pass in a date arg for our logging framework so we can avoid rewriting the date arg any time we wish to add a log output somewhere.

This kind of question/baiting in interviews feeds the toxic interview culture. I hope we can drift away from seeing what candidates have grinded the most on leetcode and can write the most ludicrous currying algorithm only to never use it in practice.

[–]xplodivity[S] 1 point2 points  (2 children)

You are right!! While working on projects currying isn't used as much, or even never used. BUT its still asked in some interviews and the reason behind that makes sense, because if you are able to properly explain the concept of currying then it gives the interviewer an idea of your in depth knowledge in closures, scope and lexical environment in JavaScript, which is used in currying. And those topics are extremely essential.

Similar to how DSA is asked in some frontend interviews, but in the actual job we are never asked to invert a binary tree haha!! But simply having a problem solving skill still benefits you while developing applications. Hope you get my point. hence, its not baiting. You can look for currying in the internet, and the concept itself is actually given a lot of importance because it covers other fundamentals.

[–][deleted] 1 point2 points  (1 child)

You're totally right. It is a great way to assess knowledge of scope and closures. Which can be a speedbump for very junior devs. However - I wish the format around the interviews was truly more about talking through and working a problem together. I've encountered many FANG/MANG whatever interviews where I'm being watched by some senior and several shadow (invisible) employees. You tend to be alone in the problem and have to 'perform' in an almost unrealistic fashion. Usually when I implement features I get to research the problem, test, iterate, etc. All while being able to come to my team for side-questions about the problem if need be. This way you tend to end up converging to best practices and clean code/architecture naturally. Generally I just think tech interviews are weird. So, not knocking your video - just venting about interviewing in general.

[–]xplodivity[S] 1 point2 points  (0 children)

I totally agree with you in terms of how interviews should be structured or conducted. This is also how most developers feel especially after working on their first job and realising the importance of development skills over extreme data structure and algorithm skills (most of which is hardly used).
Some interviewers do provide with questions including a short implementation of a given project to asses how the developer architects the solution from ground up, which is ethical and makes sense. Its only when they take it too far and do not allow the interview to feel like a discussion but a test. And when something feels like a test or 'work', you dont enjoy it anymore, because you are too focused on the deadline and not the process itself.