success_logo

Your form has successfully submitted

One of our teammates will get back to you soon.

Ruby - Now With Better Currying

Improved syntax for currying in Ruby makes it more pleasant for functional programmers. We describe how currying has changed to make it less verbose to partially apply functions.


For aficionados of functional programming, currying is a must. According to Wikipedia, "currying is the 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." 1

Currying is considered such a fundamental part of functional programming that languages like Haskell curry by default. After doing more development in Haskell, I've lamented the verbosity of using currying in Ruby. To curry a method, you had to first grab a reference to that method, then turn that method into a proc, and finally tell it to work with partial application:

> def add a, b ; a + b; end
=> :add
> method(:add).to_proc.curry
=> #<Proc:0x007fa9e2140af8 (lambda)>

This just changed yesterday in Ruby head, and you can now call curry directly on an instance of the Method class!

> def add a, b ; a + b; end
=> :add
> method(:add).curry
=> #<Proc:0x007fa9e2140af8 (lambda)>

Although this is a relatively minor change, it's a step in the right direction for functional programming in Ruby. Kudos to Arne Brasseur for making this change!

Published on: Jun. 20, 2014

Written by:


Software developer

Justin Leitgeb