博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linqjs
阅读量:6316 次
发布时间:2019-06-22

本文共 4895 字,大约阅读时间需要 16 分钟。

Project Description

linq.js - LINQ for JavaScript
Features

  • implement all .NET 4.0 methods and many extra methods (inspiration from , , Haskell, Ruby, etc...)
  • complete lazy evaluation
  • full IntelliSense support for VisualStudio
  • two versions - linq.js and jquery.linq.js (jQuery plugin)
  • support Windows Script Host
  • binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator -> see 
  • NuGet install support(, , )

90 Methods
Aggregate, All, Alternate, Any, Average, BufferWithCount, CascadeBreadthFirst, CascadeDepthFirst, Catch, Choice, Concat,
Contains, Count, Cycle, DefaultIfEmpty, Distinct, Do, ElementAt, ElementAtOrDefault, Empty, Except, Finally, First, FirstOrDefault, 
Flatten, ForEach, Force, From, Generate, GetEnumerator, GroupBy, GroupJoin, IndexOf, Insert, Intersect, Join, Last, LastIndexOf,
LastOrDefault, Let, Matches, Max, MaxBy, MemoizeAll, Min, MinBy, OfType, OrderBy, OrderByDescending, Pairwise, PartitionBy, 
Range, RangeDown, RangeTo, Repeat, RepeatWithFinalize, Return, Reverse, Scan, Select, SelectMany, SequenceEqual, Share, Shuffle,
Single, SingleOrDefault, Skip, SkipWhile, Sum, Take, TakeExceptLast, TakeFromLast, TakeWhile, ThenBy, ThenByDescending, ToArray,
ToDictionary, ToInfinity,ToJSON, ToLookup, ToNegativeInfinity, ToObject, ToString, Trace, Unfold, Union, Where, Write, WriteLine, Zip

  • see details - 

Starting linq.js ver.3.0.0-beta!(2012/07/19)

 @2013/06/20

or NuGet Install-Package linq.js -Pre, linq.js-jQuery -Pre, linq.js-RxJS -Pre, linq.js-QUnit -Pre
Now TypeScript Generics(0.9) support!
Please try it! and give me a feedback!

Query objects or json

  • sample from http://twitter.com/statuses/public_timeline.json
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" }]// ["b_mskk:kabushiki kaisha", "c_bill:g", "d_linq:to objects"]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 selectorvar queryResult2 = Enumerable.From(jsonArray)    .Where("$.user.id < 200")    .OrderBy("$.user.screen_name")    .Select("$.user.screen_name + ':' + $.text")    .ToArray();

High compatibility with C# Linq

// 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 functionEnumerable.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 - lambda expressionEnumerable.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}]// C# - AnonymousTypearray.Select((val, i) => new { Value = val, Index = i });// linq.js - object literalEnumerable.From(array).Select("val,i=>{Value:val, Index:i}")

jQuery plugin version

// $.Enumerable$.Enumerable.Range(1, 10).Where("$%2==0").ForEach("alert($)");// TojQuery - Enumerable to jQuery$.Enumerable.Range(1, 10)    .Select(function (i) { return $("

linq-jquery.jpg

IntelliSense vsdoc

linqjs_intellisense.jpg

video - using with Visual Studio 2010

video - how to debug linq.js

 

with Windows Script Host

// get folder name and file name...var dir = WScript.CreateObject("Scripting.FileSystemObject").GetFolder("C:\\"); // normallyvar itemNames = [];for (var e = new Enumerator(dir.SubFolders); !e.atEnd(); e.moveNext()){    itemNames.push(e.item().Name);}for (var e = new Enumerator(dir.Files); !e.atEnd(); e.moveNext()){    itemNames.push(e.item().Name);}// linq.jsvar itemNames2 = Enumerable.From(dir.SubFolders).Concat(dir.Files).Select("$.Name").ToArray(); 原文链接:https://archive.codeplex.com/?p=linqjs

转载于:https://www.cnblogs.com/coce/p/8644123.html

你可能感兴趣的文章
saprk里面的action - aggregate
查看>>
ABP框架系列之四十八:(Specifications-规范)
查看>>
面向切面编程(AOP)简介
查看>>
转眼人到中年:前端老程序员无法忘怀的一次百度电话面试(二)
查看>>
基于FPGA的异步FIFO验证
查看>>
selenium+python自动化90-unittest多线程执行用例
查看>>
固定二进制位的整型变量
查看>>
Metasploit自动攻击模块
查看>>
人工智能头条技能树图谱汇集
查看>>
我最在行 汉字
查看>>
[100]第三波常用命令
查看>>
haproxy实现会话保持(1):cookie
查看>>
Apache + PHP配置
查看>>
《学习》11触发器
查看>>
数组以字符串记录(字符串转数组)
查看>>
nginx ngscript 简单使用
查看>>
[Elasticsearch] 多字段搜索 (五) - 以字段为中心的查询
查看>>
Intelij U
查看>>
如何mount一个Isilon的NFS的file share?
查看>>
Android模仿三星手机系统滑动条滑动时滑块变大的特效
查看>>