Tinco's Blog

Playing with ruby: Currying, Higher Order Methods

Today I felt a bit ill, so I sat back and played some games.. with Ruby ofcourse :P

First I helped some dude with merging two hashes:

That made me think about how it would be nice to be able to do: [first_value, second_value].any.is_a? Array

So I implemented that:

The HigherOrderMethod class was first called LazyIterator, because I didn’t know what it was. Apeiros enlightened me so I renamed it. I pasted that code to some friends and we started discussing about wether Ruby was ugly or not. Someone asked if Ruby supported currying, I didn’t know what it was, so they explained it to me. At first I thought ruby didn’t support it, so I implemented it:

But afterwards I found out that Ruby 1.9 has Proc#curry, so it is possible, but not with default lambda’s and procs.

So that was a friday afternoon/night well wasted :)

Post a comment


(lesstile enabled - surround code blocks with ---)