This project is read-only.
Project Description
This is a linq like implementation for typescript. Because typescript gets compiled into javascript, you can use this library for common javascript too.


**TsLinq - Linq implementation for typescript**

I am a hughe fan of linq in C# and I'm using it heavily. When using typescript, this functionallity was missed which forces me to create this small library. It contains some C# like implementations of List<T> and IEnumerable<T> and other common helpers.

The linq methods where implemented like in C#. This is not a copy of the C# implementation, it is an own implementation but the interfaces are similar to C# linq.

This library has no references to other frameworks and should work with every other third party frameworks. There is an package reference to JQuery in the project, but jquery is only used for bringing up the test script html page.

This library is not intended to be a full implementation of the Linq library for C#. If you miss some methods / functionallity, let me know or join this project to work with me together.

In folder under the web src\tests you can find simple unit tests for the functionallity which is provided by the library. You can use this tests for reviewing the functionallity and way of working of TsLinq.

Other Linq frameworks / Comparision

There are other linq framework out.
Here is one on GitHub with the same name after starting this project:
https://github.com/brunolm/TSLinq
This project has a dependency on JQuery. I dont have tried it.

Underscore.js implements similar functionallity as Linq queries does, but the implement differs very much. So I have not taken into account to use that library.

Another Linq framework for plain javascript is Linq.js (on Codeplex). I have made performance tests which are comparing linq.js and TsLinq.

Here is a preview of the output from the comparision with Linq.JS. As you can see, TsLinq is much more faster (sometimes 10 times faster) than the Linq.js implementations in most cases.

I have used an array with 10,000,001 (0 til 10,000,000) numbers for my performance tests.

where(x%2==0), TsLinq: *174ms* (value: 5000001), Linq.js: 560ms (value: 5000001)
single(x == 10,000,000), TsLinq: *17ms* (value: 10000000), Linq.js: 195ms (value: 10000000)
single(x == 0), TsLinq: *102ms* (value: 0), Linq.js: 196ms (value: 0)
singleOrDefault(x==10,000,000), TsLinq: *102ms* (value: 10000000), Linq.js: 195ms (value: 10000000)
singleOrDefault(x==0), TsLinq: *102ms* (value: 0), Linq.js: 193ms (value: 0)
all(x<10,000,000), TsLinq: *18ms* (value: false), Linq.js: 302ms (value: false)
all(x<5,000,000), TsLinq: *100ms* (value: false), Linq.js: 174ms (value: false)
first(x==10,000,000), TsLinq: *14ms* (value: 10000000), Linq.js: 197ms (value: 10000000)
first(x==0), TsLinq: 0ms (value: 0), Linq.js: 0ms (value: 0)
firstOrDefault(x==10,000,000), TsLinq: *64ms* (value: 10000000), Linq.js: 197ms (value: 10000000)
firstOrDefault(x==0), TsLinq: 0ms (value: 0), Linq.js: 0ms (value: 0)
last(x==10,000,000), TsLinq: *0ms* (value: 10000000), Linq.js: 196ms (value: 10000000)
last(x==0), TsLinq: *96ms* (value: 0), Linq.js: 196ms (value: 0)
lastOrDefault(x==10,000,000), TsLinq: *0ms* (value: 10000000), Linq.js: 195ms (value: 10000000)
lastOrDefault(x==0), TsLinq: *98ms* (value: 0), Linq.js: 195ms (value: 0)
select({value:x}), TsLinq: *748ms* (value: 10000001 entries), Linq.js: 1281ms (value: 10000001 entries)
indexOf(10,000,000), TsLinq: *23ms* (value: 10000000), Linq.js: 275ms (value: 10000000)
elementAt(10,000,000), TsLinq: 0ms (value: 10000000), Linq.js: 0ms (value: 10000000)
elementAtOrDefault(10,000,000), TsLinq: 0ms (value: 10000000), Linq.js: 0ms (value: 10000000)
forEach({}), TsLinq: *94ms* (value: true), Linq.js: 297ms (value: undefined)
indexOf(10,000,000), TsLinq: *23ms* (value: true), Linq.js: 258ms (value: true)
any(x==10,000,000), TsLinq: *70ms* (value: true), Linq.js: 260ms (value: true)
count(x==10000000), TsLinq: *17ms* (value: 1), Linq.js: 346ms (value: 1)
toDictionary(x => x % 2), TsLinq: *898ms* (value: 2 keys generated), Linq.js: 1940ms (value: 2 keys generated)
groupBy(x => x % 2), TsLinq: *1072ms* (value: 2 keys generated), Linq.js: 1737ms (value: 2 keys generated)
selectMany(2 objects with 10000001 values in property values), TsLinq: *197ms* (value: 20000002 entries), Linq.js: 2198ms (value: 20000002 entries)
cast<>() was not implemented by Linq.js
aggregate((n1, n2) => n1 + n2), TsLinq: *249ms* (value: 50000005000000), Linq.js: 1136ms (value: 50000005000000)
skip(1,000,000), TsLinq: *74ms* (value: 9000001 entries), Linq.js: 748ms (value: 9000001 entries)
take(10,000,000), TsLinq: *166ms* (value: 10000000 entries), Linq.js: 973ms (value: 10000000 entries)
intersect(2 lists á 10000 entries), TsLinq: 274ms (value: 10000 entries), Linq.js: *12ms* (value: 10000 entries)
except(2 lists á 10000 entries), TsLinq: 123ms (value: 0 entries), Linq.js: *5ms* (value: 0 entries)
concat(with 10000 entries), TsLinq: *11ms* (value: 10010001 entries), Linq.js: 927ms (value: 10010001 entries)
reverse(), TsLinq: *438ms* (value: 10000001 entries), Linq.js: 806ms (value: 10000001 entries)
zip(addition of a collection of the same content), TsLinq: *158ms* (value: 10000001 entries), Linq.js: 1109ms (value: 10000001 entries)
min(), TsLinq: *88ms* (value: 0), Linq.js: 1829ms (value: 0)
min(x*2), TsLinq: *154ms* (value: 0), Linq.js: 1918ms (value: 0)
max(), TsLinq: *90ms* (value: 10000000), Linq.js: 1906ms (value: 10000000)
max(x*2), TsLinq: *158ms* (value: 20000000), Linq.js: 1909ms (value: 20000000)
distinct(modulo from 2 of all items), TsLinq: *94ms* (value: 2 entries), Linq.js: 1379ms (value: 2 entries)
union(2 arrays á 10000 entries), TsLinq: 300ms (value: 10000 entries), Linq.js: *8ms* (value: 10000 entries)

Last edited Jun 2, 2014 at 1:35 PM by mbaarz, version 24