Git Product home page Git Product logo

linq's Introduction

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

linq's People

Contributors

mihaifm avatar stschnell avatar smdern avatar noy-shimotsuki avatar m0ns1gn0r avatar miquik avatar ejuke avatar zastrowm avatar scriby avatar 304notmodified avatar mastodon0 avatar ugaya40 avatar neuroboy23 avatar styfle avatar tuan-tu-tran avatar cervengoc avatar zhongchengyi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.