Make your code readable. Pretend the next person who looks
at your code is a psychopath and they know where you live.
-- Philip Wadler
Curry all over the C++11
August 7, 2013
- Ivan Čukić
Currying is all-present in functional programming. And we are not really using
What is currying? It is a technique of transforming a function that takes
multiple arguments in such a way that it can be called as a chain of functions,
each with a single argument.
For example, lets look at a simpler version of fprintf function that looks
something like this:
If we use the method often with specific streams (like cout, cerr and a log
file), we can define it in a different manner, so that we could easily
make additional versions specific to those streams. And, we don’t need to
impose our opinions of what a user wants by providing a set of convenience
functions ourselves (ok, qDebug() is something that everybody wants, but you
get the point).
So, this seems totally unneeded, right? It can be quite useful when working
with generic code (for example STL algorithms). The following example
demonstrates vector partitioning for different predicates.