~~ Offline ~~ theme Menu

Is this functional code?

I’m an Object Oriented (OO) kind of guy, maybe a bigot. I have read a very large number of OO books and I’ve written a fair amount of OO code in my 10+ years in this industry. I’m afraid my mind is wired for OO at this point, for good or bad.

Recently, I’ve been getting interested in functional languages. The most functional guys around here are Wes and Luke, while Dr. T has somehow transcended the whole thing.

Here is the text of one of my newbie emails to Dr.T. I’ll let you think about it for a bit before posting his reply. The phrase: “Is this it?” has to be read as “Is this what functional programming is all about?".


Is this it? I have about four of these ‘delegate taking’ functions in my excel addin ….

    delegate bool PredWithPrevious<T>(T value, T previous);
static int CountWithPrevious<T>(IEnumerable<T> en, PredWithPrevious<T> pred) {

int count = 0;
T previous = default(T);
bool isPrevious = false;

foreach (T val in en) {

if (isPrevious)
if (pred(val, previous))
previous = val;
isPrevious = true;
return count;