Last week, I talked about currying a little bit, and I’ve been thinking about how one could do in languages that don’t have it built in. It can be done in Java, but the type of even a two-parameter function would be something like Function<Integer, Function<Integer, Integer>>, which is bad enough. Imagine 3- or 4-parameter functions.
There’s also the fact that calling curried functions doesn’t look good. Calling the two-parameter function with both parameters would look something like func.apply(1).apply(2). This isn’t what we want. At worst, we want to be stuck with func(1)(2), but that’s not possible in Java. At best, we want to be able to choose func(1)(2) (calling it with the first argument at one point in time and using the second one later) OR func(1, 2), depending on our current need. It’s possible to do so in python, so I’m using that. Continue Reading