Skip Navigation Links

LINQ and higher order functions

Categories

While not a new concept, higher order functions are currently very much in vogue, especially with the new found interest in dynamic languages. But your statically typed (.net) languages can enjoy higher order functions, too, thanks to delegates (and for the old school C/C++ programmer, plain old function pointers and the STL).

Dustin Campbell has a great post describing the concept and giving plenty of examples for .net 2.0. The interesting part is where he introduces us to the old stalwarts of list manipulations - filter, map and reduce.

It's a popular post that has been linked to lots of times, but I've seen very few links to the follow up post. Here, Dustin sets of a light bulb in my head by pointing out that the LINQ commands are really just implementations of filter, map and reduce (the keywords where and select and the Aggregate extension method, respectively). This was an aha moment for me that changed the emphasis of LINQ. It's easy to get distracted by the SQL-like syntax and the LINQ to SQL database integration, and not notice that LINQ to objects is not so much about querying than it is about sequence manipulation, where sequences can be more than simple lists.

This really opens LINQ up for me. I can think of plenty of places to use it now. Reducing Dare's many loops to a single loop over the results is just a great example.

posted 1/7/2008 12:14:28 PM

 

Comments:

There are no comments to display for this post.

 

Name:  
Url (optional):  
Subject:  
Comment:  

Enter Captcha Validation:
(If you cannot read the Captcha image, press "Reset Image" to generate a new one)