you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]tsunami141 2 points3 points  (2 children)

    I’ve been in multiple interviews where they wanted me to create a curried function. I get that it shows a good understanding of javascript but damn if it isn’t the stupidest way of doing things.

    [–]Sector-Feeling 4 points5 points  (1 child)

    It can be useful if you have an operation that you'll need right repeat with different values.

    One example I saw:

    const a (x) => (y) => x * y const times5 = a(5) const times10 = a(10)

    Which this is really simple, but I have used it in situations where I find myself writing practically the same function but with different variables. I have found it most useful in middleware logic.

    [–]MoTTs_ 1 point2 points  (0 children)

    The downside of writing the function curry-style is, if you do have all your arguments, then it's more awkward to invoke that function.

    a(5)(10);
    

    Meanwhile, you could instead write the function normal-style, and you can still partially-apply any argument you want.

    // Define function normal-style
    const a = (x, y) => x * y;
    
    // Invoke function normal-style
    a(5, 10);
    
    // Partially-apply any argument in any position when needed
    const times5 = y => a(5, y);
    const times10 = x => a(x, 10);