Skip to content
/ linq Public
forked from mihaifm/linq

linq.js - LINQ for JavaScript

License

Notifications You must be signed in to change notification settings

StSchnell/linq

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

linq

This is a JavaScript implementation of the .NET LINQ library.
It contains all the original .NET methods plus a few additions and it is written in pure JavaScript with no dependencies.
This is a fork with the addition to use linq with the Rhino JavaScript engine.

Examples

// C# LINQ - delegate
Enumerable.Range(1, 10)
    .Where(delegate(int i) { return i % 3 == 0; })
    .Select(delegate(int i) { return i * 10; });

// linq.js - anonymous function
Enumerable.range(1, 10)
    .where(function(i) { return i % 3 == 0; })
    .select(function(i) { return i * 10; });
// C# LINQ - lambda
Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);

// linq.js - arrow function
Enumerable.range(1, 10).where((i) => i % 3 == 0).select((i) => i * 10);
// C# LINQ - anonymous type
array.Select((val, i) => new { Value: val, Index: i }());

// linq.js - object literal
Enumerable.from(array).select((val, i) => ({ value: val, index: i }));

See sample/tutorial.js and the test folder for more examples.

Usage

Rhino

This engine is programmed in Java and generates a class from the compiled JavaScript code. It was bundled with Java SE 6 and used as a programming interface in some business products. Rhino can be used with Java 8 and above and is mostly compatible with the ECMAScript 5 standard. To use linq with Rhino, download the latest linq release and modify it as it is described here.

After these preparations you can load it in your code with load command and use it:

load("linq.class.js");
var result = Enumerable.range(1, 10)
  .where( function(i) { return i % 3 == 0 } )
  .select( function(i) { return i * 10 } );
java.lang.System.out.println(
  JSON.stringify(result.toArray())
); // [ 30, 60, 90 ]

Credits

Yoshifumi Kawai developed the original version of this library.

License

MIT License

About

linq.js - LINQ for JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.8%
  • Batchfile 0.2%