Currying vs. Partial Application (2015)
11–20 of 54 posts
Re: Currying vs. Partial Application (2015)
#12I love how the new arrow syntax makes curried functions incredibly simple. const fn = a => b => c => { return a + b + c; };
appear incredibly simple*️
Re: Currying vs. Partial Application (2015)
#13Ok, it might be too early in the morning, but I still don't understand this. I read that post, and the post by 'raganwald that the former linked to, and I still don't see any difference between currying and partial application. And yet both posts seem to imply (without showing in any way) that the two concepts are different. How come?
https://hughfdjackson.com/javascript/why-curry-helps/
Basically a curried function could be described nested series of partially applied functions(one argument per step).
On a side note to me this article is a bit on the heavy side when it comes to conveying the message. For one thing partial application should be explained first.
Re: Currying vs. Partial Application (2015)
#14Currying in JavaScript is really nice if you can remember the arities of each curried function you're using. If you forget to call up to the last argument, you'll be passing a curried function instead of the expected value, and it can throw an error really far away from the bug. And instead of normal data to inspect at the error site to point you to the bad call, you'll only have a generic function name to look at. I…
One reason for that is that my curried functions and their derivatives are usually named in a way that says exactly what they do.
Re: Currying vs. Partial Application (2015)
#15Re: Currying vs. Partial Application (2015)
#16I wrote my own curry using the pareto principle - this works for 80% of my use cases (or more): const curry = (fn,b) => (a) => fn(a,b);
Are you typically not binding the first parameter? Why?
Re: Currying vs. Partial Application (2015)
#17Ok, it might be too early in the morning, but I still don't understand this. I read that post, and the post by 'raganwald that the former linked to, and I still don't see any difference between currying and partial application. And yet both posts seem to imply (without showing in any way) that the two concepts are different. How come?
Re: Currying vs. Partial Application (2015)
#18Currying in JavaScript is really nice if you can remember the arities of each curried function you're using. If you forget to call up to the last argument, you'll be passing a curried function instead of the expected value, and it can throw an error really far away from the bug. And instead of normal data to inspect at the error site to point you to the bad call, you'll only have a generic function name to look at. I…
The type of a curried function in Typescript is just something like: (a: number) => (b: number) => (c: number) => number Sure, the parameter names and parentheses are a bit annoying, but I wouldn't call that "very verbose". Comparable concepts in C++ or Java would be a nightmare to type out.
Maybe just a matter of perception but it looks verbose to me.
Re: Currying vs. Partial Application (2015)
#19Ok, it might be too early in the morning, but I still don't understand this. I read that post, and the post by 'raganwald that the former linked to, and I still don't see any difference between currying and partial application. And yet both posts seem to imply (without showing in any way) that the two concepts are different. How come?
Currying:
const f = x => y => x + y;
const g = f(1);
const sum = g(2);
Partial application: const f = (x, y) => x + y;
const g = _ => f(1, _);
const sum = g(2);
Most FP languages have nicer syntax for this.Re: Currying vs. Partial Application (2015)
#20Earlier quoted context omitted.
The type of a curried function in Typescript is just something like: (a: number) => (b: number) => (c: number) => number Sure, the parameter names and parentheses are a bit annoying, but I wouldn't call that "very verbose". Comparable concepts in C++ or Java would be a nightmare to type out.
I agree, that doesn't look bad. However, this type definition forces you to supply one argument per function call, which looks awful in JavaScript: fn(1)(2)(3) That's a big drawback for me. Libraries like Ramda allow one or more arguments per function call: fn(1, 2, 3) === fn(1, 2)(3) === fn(1)(2, 3) That's what makes the verbosity unbearable, as each type of call needs its own type.
Here's a gist of the type definitions I'm using: https://gist.github.com/noppa/c600cc43fd44e33768efe6c6eec4a9...
I think something similar might work in TS too.
Demo: https://goo.gl/w3aPsw