Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khusnetdinov/linq
This gem is wrapper for linq.js JavaScript plugin. Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 (That moment for #C, VisualBasic) that extends powerful query capabilities to the language syntax. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store.
https://github.com/khusnetdinov/linq
javascript jquery linq linq-javascript-plugin ruby-gem wrapper
Last synced: 3 months ago
JSON representation
This gem is wrapper for linq.js JavaScript plugin. Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 (That moment for #C, VisualBasic) that extends powerful query capabilities to the language syntax. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store.
- Host: GitHub
- URL: https://github.com/khusnetdinov/linq
- Owner: khusnetdinov
- Created: 2015-06-05T09:52:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-08T09:45:28.000Z (over 9 years ago)
- Last Synced: 2024-10-09T13:07:15.927Z (4 months ago)
- Topics: javascript, jquery, linq, linq-javascript-plugin, ruby-gem, wrapper
- Language: Ruby
- Homepage:
- Size: 188 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Linq
This gem is wrapper for linq.js JavaScript plugin. Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 (That moment for #C, VisualBasic) that extends powerful query capabilities to the language syntax. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store.
## Features
- Implement all .NET 4.0 methods and many extra methods (inspiration from Rx, Achiral, Haskell, Ruby, etc...)
- Complete lazy evaluation
- Two versions - linq.js and jquery.linq.js (jQuery plugin)
- Binding for Reactive Extensions for JavaScript(RxJS)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'linq'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install linq
Add to javascript manifest `application.js`
//= require linq## Examples of usage
```javascript
var jsonArray = [
{ "user": { "id": 100, "screen_name": "d_linq" }, "text": "to objects" },
{ "user": { "id": 130, "screen_name": "c_bill" }, "text": "g" },
{ "user": { "id": 155, "screen_name": "b_mskk" }, "text": "kabushiki kaisha" },
{ "user": { "id": 301, "screen_name": "a_xbox" }, "text": "halo reach" }
]var queryResult = Enumerable.From(jsonArray)
.Where(function (x) { return x.user.id < 200 })
.OrderBy(function (x) { return x.user.screen_name })
.Select(function (x) { return x.user.screen_name + ':' + x.text })
.ToArray();
// shortcut! string lambda selector
var queryResult2 = Enumerable.From(jsonArray)
.Where("$.user.id < 200")
.OrderBy("$.user.screen_name")
.Select("$.user.screen_name + ':' + $.text")
.ToArray();
```More tricky:
```javascript
// anonymous function
Enumerable.Range(1, 10)
.Where(function(i) { return i % 3 == 0; })
.Select(function(i) { return i * 10; });
// lambda expression
Enumerable.Range(1, 10).Where("i => i % 3 == 0").Select("i => i * 10");// $ is default iterator variable like Scala's "_" or Groovy's "it"
Enumerable.Range(1, 10).Where("$ % 3 == 0").Select("$ * 10");// "" is shorthand of "x => x" (identity function)
Enumerable.Range(4, 7).Join(Enumerable.Range(8, 5), "", "", "outer,inner=>outer*inner");// Enumerable.From is wrap from primitive array, string(to charArray), object(to KeyValuePair[]) etc..
var array = [100, 200, 30, 40, 500, 40, 200];
var ex1 = Enumerable.From(array).Distinct().ToArray(); // [100, 200, 30, 40, 500]
var ex2 = Enumerable.From("foobar").ToArray(); // ["f", "o", "o", "b", "a", "r"];
var ex3 = Enumerable.From({foo:10, bar:20}).ToArray(); // [{Key:"foo",Value:10}, {Key:"bar",Value:20}]// object literal
Enumerable.From(array).Select("val,i=>{Value:val, Index:i}")
```
And Jquery:```javascript
// $.Enumerable
$.Enumerable.Range(1, 10).Where("$ % 2 == 0").ForEach("alert($)");// TojQuery - Enumerable to jQuery
$.Enumerable.Range(1, 10)
.Select(function (i) { return $("").text(i)[0] })
.TojQuery()
.appendTo("#select1");// toEnumerable - jQuery to Enumerable
var sum = $("#select1").children()
.toEnumerable()
.Select("parseInt($.text())")
.Sum(); // 55
```Full [documentation is on the wiki][wiki]
[wiki]: https://github.com/khusnetdinov/linq/wiki