Editorials

LinqJs

Today I was introduced to a library new to me that has been out there for more than 6 years. LinqJs is a library bringing Linq styled syntax to the JavaScript world.

At the core, what Linq does for you is to remove all of the iteration logic from your visible code so that the things that you are intending to accomplish are not hidden behind all of the gymnastics of Enumeration. Enumeration is the technique of walking through a set of data for the purpose of applying some behavior to each record.

LinqJs begins by creating an IEnumerable wrapper around JavaScript sets, ie, arrays. Then it begins to add set operations you may call to apply against a set of objects transformed by the Enumeration function. Walking through the JavaScript code demonstrates some idea of how Microsoft may have implemented Linq in Dot Net.

For example, the LinqJs library has a function Where. You pass a function to the Where function. You function is applied to each record as it is enumerated, and based on a true/false value from your function, includes or excludes each record in the output.

There are many other functions which may be of interest for you to view. Join, Intersect, Except, Group By, Take, Skip, etc. are some of the many functions already available. If you are of a mind you can implement your own extensions to the library. You can get the library from github.com/neuecc/linq.js.

Cheers,

Ben