Jquery.Linq用法

上官砚文
2023-12-01

下载:http://linqjs.codeplex.com/

 

LINQ Pad

Enumerable.Range(0, 20)
.Where("$ % 3 == 0")
.Select("value, index => {index:index, value:value * 10}")
.WriteLine("$.index + ':' + $.value")

 

0:0
1:30
2:60
3:90
4:120
5:150
6:180

Generating Methods

method namereturn typeargumentsexample (click code)
ChoiceEnumerableparams T obj
Enumerable.Choice("a","b","c","d").Take(10)
Enumerable.Choice(["a","b","c","d"]).Take(10)
CycleEnumerableparams T obj
Enumerable.Cycle(1,"foo",true).Take(10)
Enumerable.Cycle([1,"foo",true]).Take(10)
EmptyEnumerable()
Enumerable.Empty()
FromEnumerableArray obj
var arr = [1,124,"aaa",function(){},false];
Enumerable.From(arr)
Object obj
var obj = {a:3,b:"3",z:function(){},d:true};
Enumerable.From(obj).Select("$.Key + ':' + $.Value")
NodeList obj
var node = document.getElementsByTagName("h2");
Enumerable.From(node).Select("$.innerHTML")
Number obj
Enumerable.From(5)
String obj
Enumerable.From("foobar")
IEnumerable(WSH) obj
// using with Windows Script Host
// var fso = WScript.CreateObject("Scripting.FileSystemObject");
// var files = fso.GetFolder("C:\\").Files;
// Enumerable.From(files).Select("$.Name").ForEach("WScript.Echo($)");
ReturnEnumerableT element
Enumerable.Return("foobar")
MatchesEnumerablestring input, RegExp pattern
Enumerable.Matches("xbcyBCzbc", /(.)bc/i)
.Select("'index='+$.index+' all='+$[0]+' capture='+$[1]")
string input, string pattern
Enumerable.Matches("xbcyBCzbc", "(.)bc")
.Select("'index='+$.index+' all='+$[0]+' capture='+$[1]")
string input, string pattern, string flags
Enumerable.Matches("xbcyBCzbc", "(.)bc", "i")
.Select("'index='+$.index+' all='+$[0]+' capture='+$[1]")
RangeEnumerableint start, int count
Enumerable.Range(10,5)
int start, int count, int step
Enumerable.Range(10,5,3)
RangeDownEnumerableint start, int count
Enumerable.RangeDown(10,5)
int start, int count, int step
Enumerable.RangeDown(10,5,3)
RangeToEnumerableint start, int to
Enumerable.RangeTo(10,18)
Enumerable.RangeTo(3,-5)
int start, int to, int step
Enumerable.RangeTo(1,9,3)
Enumerable.RangeTo(1,-9,3)
RepeatEnumerableT obj
Enumerable.Repeat(3).Take(5)
T obj, int count
Enumerable.Repeat("foo",10)
RepeatWithFinalizeEnumerableT initializer(), void finalizer(T)
// example for WScript(Text EnumerateLines and Finally Close)
// var fso = WScript.CreateObject("Scripting.FileSystemObject");
// Enumerable.RepeatWithFinalize(
//         function () { return fso.OpenTextFile("C:\\file.txt") },
//         function (ts) { ts.Close() })
//     .TakeWhile(function (ts) { return !ts.AtEndOfStream })
//     .Select(function (ts) { return ts.ReadLine() });
GenerateEnumerableT func()
Enumerable.Generate("Math.random()").Take(5)
T func(), int count
Enumerable.Generate("Math.random()", 5)
ToInfinityEnumerable()
Enumerable.ToInfinity().Take(5)
int start
Enumerable.ToInfinity(1000).Take(5)
int start, int step
Enumerable.ToInfinity(1000,5).Take(5)
ToNegativeInfinityEnumerable()
Enumerable.ToNegativeInfinity().Take(5)
int start
Enumerable.ToNegativeInfinity(1000).Take(5)
int start, int step
Enumerable.ToNegativeInfinity(1000,5).Take(5)
UnfoldEnumerableT seed, T func(T)
Enumerable.Unfold(5, "$+3").Take(10)

Projection and Filtering Methods

method namereturn typeargumentsexample (click code)
CascadeBreadthFirstEnumerableT[] func(T)
Enumerable.Return(1).CascadeBreadthFirst("$+$").Take(5)
T[] func(T), T resultSelector(T)
Enumerable.Return(1).CascadeBreadthFirst("$+$","$*$").Take(5)
T[] func(T), T resultSelector(T, int)
Enumerable.Return(document.body)
.CascadeBreadthFirst("$.childNodes", "v,n=>{value:v,nestLevel:n}")
.Where("$.nestLevel<3 && $.value.nodeType == 1")
.Select("$.nestLevel + ':' + $.value.tagName")
CascadeDepthFirstEnumerableT[] func(T)
Enumerable.Return(1).CascadeDepthFirst("$+$").Take(5)
T[] func(T), T resultSelector(T)
Enumerable.Return(1).CascadeDepthFirst("$+$","$*$").Take(5)
T[] func(T), T resultSelector(T, int)
Enumerable.Return(document.body)
.CascadeDepthFirst("$.childNodes", "v,n=>{value:v,nestLevel:n}")
.Where("$.nestLevel<3 && $.value.nodeType == 1")
.Select("$.nestLevel + ':' + $.value.tagName")
FlattenEnumerable()
var array = [1,[234,2,[62,3]],[234,5],3];
Enumerable.From(array).Flatten()
PairwiseEnumerableT selector(T, T)
Enumerable.Range(1,10)
.Pairwise("prev,next=>prev + ':' + next")
ScanEnumerableT func(T, T)
Enumerable.Range(1,10).Scan("a,b=>a+b")
T seed, T func(T, T)
Enumerable.Range(1,10).Scan(100,"a,b=>a+b")
T seed, T func(T, T), T resultSelector(T)
Enumerable.Range(1,10).Scan(100,"a,b=>a+b","$*10")
SelectEnumerableT selector(T)
Enumerable.Range(1,10).Select("$*10")
T selector(T, int)
Enumerable.RangeDown(10,10).Select("value,index=>index + ':' + value")
SelectManyEnumerableT[] collectionSelector(T)
Enumerable.Range(1,3).SelectMany("Enumerable.Repeat($,3)")
T[] collectionSelector(T, int)
Enumerable.Range(5,5)
.SelectMany("value,index=>Enumerable.Repeat('str'+value,index+1)")
T[] collectionSelector(T), resultSelector(T, T)
Enumerable.Range(1,3)
.SelectMany("Enumerable.Repeat($,3)","first,middle=>first + ':' + middle*10")
T[] collectionSelector(T, int), resultSelector(T, T)
Enumerable.Range(5,5)
.SelectMany("v,i=>Enumerable.Repeat('str'+v,i+1)","f,m=>f + ':' + m")
WhereEnumerablebool predicate(T)
Enumerable.Range(1,10).Where("$%2==0")
bool predicate(T, int)
Enumerable.Range(1,10).Where("value,index=>value*index>10")
OfTypeEnumerableClass type
Enumerable.From([1,"a",2,"b","c",3]).OfType(Number)
Enumerable.From([1,"a",2,"b","c",3]).OfType(String)
function ClassA(v){this.v = v}
Enumerable.From([new ClassA("a"),1,2,new ClassA("b")])
    .OfType(ClassA).Select("$.v")
ZipEnumerableT[] second,T selector(T, T)
Enumerable.RangeDown(10,10)
.Zip(Enumerable.Range(1,10),"outer,inner=>outer + ':' + inner")
T[] second,T selector(T, T, int)
Enumerable.RangeDown(10,10)
.Zip(Enumerable.Range(1,10),"outer,inner,index=>index + ':' + outer*inner")

Join Methods

method namereturn typeargumentsexample (click code)
JoinEnumerableT[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, T)
var array1 = [13,413,5,135,61,631,13,61,3];
var array2 = [13,134,53,6,3,7,13,7,7,135,61,3,13];
Enumerable.From(array1)
.Join(array2,"","","outer,inner=>outer + ':' + inner")
T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, T), T compareSelector(T)
var array1 = [10,405,50,135];
var array2 = [1,4,7,8];
Enumerable.From(array1)
.Join(array2,"","","outer,inner=>outer + ':' + inner","$%2==0")
GroupJoinEnumerableT[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, Enumerable)
var array1 = [13,413,5,135,61,631,13,61,3];
var array2 = [13,134,53,6,3,7,13,7,7,135,61,3,13];
Enumerable.From(array1)
.GroupJoin(array2,"","","outer,lookup=>outer + ':' + lookup.ToString('-')")
T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, Enumerable), T compareSelector(T)
var array1 = [10,405,50,135];
var array2 = [1,4,7,8];
Enumerable.From(array1)
.GroupJoin(array2,"","","outer,lookup=>outer + ':' + lookup.ToString('-')","$%2==0")

Set Methods

method namereturn typeargumentsexample (click code)
AllBooleanbool predicate(T)
Enumerable.Range(1,10).All("$<5")
Enumerable.Range(1,10).All("$<15")
AnyBoolean()
Enumerable.Range(1,0).Any()
Enumerable.Range(1,10).Any()
bool predicate(T)
Enumerable.Range(1,10).Any("$==5")
Enumerable.Range(1,10).Any("$==15")
ConcatEnumerableT[] second
Enumerable.Range(1,5).Concat(Enumerable.Repeat("foo",5))
InsertEnumerableint index, T[] second
Enumerable.Range(1,5).Insert(3,Enumerable.Repeat("foo",5))
AlternateEnumerableT value
Enumerable.Range(1,5).Alternate(-1)
ContainsBooleanT value
Enumerable.Range(1,5).Contains(3)
Enumerable.Range(1,5).Contains(10)
T value, T compareSelector(T)
Enumerable.Range(1,5).Select("{test:$}").Contains(3)
Enumerable.Range(1,5).Select("{test:$}").Contains(3,"$.test")
DefaultIfEmptyEnumerableT defaultValue
Enumerable.Range(1,5).DefaultIfEmpty("default")
Enumerable.Range(1,0).DefaultIfEmpty("default")
DistinctEnumerable()
var array = [1,412,5,3,5,412,7];
Enumerable.From(array).Distinct()
T compareSelector(T)
var seq = Enumerable.Range(1,10).Select("{test:$%3}");
seq.Distinct("$.test").Select("$.test")
ExceptEnumerableT[] second
var array1 = [1,412,5,3,5,412,7];
var array2 = [20,12,5,5,7,310];
Enumerable.From(array1).Except(array2)
T[] second, T compareSelector(T)
var seq1 = Enumerable.Range(1,10).Select("{test:$%5}");
var seq2 = Enumerable.Range(1,10).Select("{test:$%2}");
seq1.Except(seq2,"$.test").Select("$.test")
IntersectEnumerableT[] second
var array1 = [1,412,5,3,5,412,7];
var array2 = [20,12,5,5,7,310];
Enumerable.From(array1).Intersect(array2)
T[] second, T compareSelector(T)
var seq1 = Enumerable.Range(1,10).Select("{test:$%5}");
var seq2 = Enumerable.Range(1,10).Select("{test:$%2}");
seq1.Intersect(seq2,"$.test").Select("$.test")
SequenceEqualBooleanT[] second
Enumerable.Range(1,5).SequenceEqual(Enumerable.Range(1,5))
Enumerable.Range(1,5).SequenceEqual(Enumerable.Range(1,6))
T[] second, T compareSelector(T)
Enumerable.Range(1,10).Select("{test:$%5}")
.SequenceEqual(Enumerable.Range(1,10).Select("{test:$%5}"),"$.test")
UnionEnumerableT[] second
var array1 = [1,412,5,3,5,412,7];
var array2 = [20,12,5,5,7,310];
Enumerable.From(array1).Union(array2)
T[] second, T compareSelector(T)
var seq1 = Enumerable.Range(1,5).Select("{test:$}");
var seq2 = Enumerable.Range(3,7).Select("{test:$}");
seq1.Union(seq2,"$.test").Select("$.test")

Ordering Methods

method namereturn typeargumentsexample (click code)
OrderByOrderedEnumerable()
var array = [1,51,61,75,8,35,43];
Enumerable.From(array).OrderBy()
T keySelector(T)
var array = [{a:"a"},{a:"z"},{a:"k"},{a:"l"},{a:"m"},{a:"c"}];
Enumerable.From(array).OrderBy("$.a").Select("$.a")
OrderByDescendingOrderedEnumerable()
var array = [1,51,61,75,8,35,43];
Enumerable.From(array).OrderByDescending()
T keySelector(T)
var array = [{a:"a"},{a:"z"},{a:"k"},{a:"l"},{a:"m"},{a:"c"}];
Enumerable.From(array).OrderByDescending("$.a").Select("$.a")
ThenByOrderedEnumerableT keySelector(T)
var list = [
           { a: 2, b: 4, c: 1 },
           { a: 2, b: 3, c: 7 },
           { a: 2, b: 3, c: 3 },
           { a: 4, b: 7, c: 5 },
           { a: 7, b: 3, c: 2 },
           { a: 4, b: 1, c: 5 }];
Enumerable.From(list).OrderBy("$.a").ThenBy("$.c").ThenBy("$.b")
.Select("$.a + ':' + $.b + ':' + $.c")
ThenByDescendingOrderedEnumerableT keySelector(T)
var list = [
           { a: 2, b: 4, c: 1 },
           { a: 2, b: 3, c: 7 },
           { a: 2, b: 3, c: 3 },
           { a: 4, b: 7, c: 5 },
           { a: 7, b: 3, c: 2 },
           { a: 4, b: 1, c: 5 }];
Enumerable.From(list).OrderBy("$.a").ThenByDescending("$.c").ThenByDescending("$.b")
.Select("$.a + ':' + $.b + ':' + $.c")
ReverseEnumerable()
Enumerable.Range(1,10).Reverse()
ShuffleEnumerable()
Enumerable.Range(1,10).Shuffle()

Grouping Methods

method namereturn typeargumentsexample (click code)
GroupByEnumerable<Grouping>T keySelector(T)
Enumerable.Range(1,5).GroupBy("$%2==0")
.Select("$.Key() + ':' + $.ToString('-')")
T keySelector(T), T elementSelector(T)
Enumerable.Range(1,5).GroupBy("$%2==0","$*10")
.Select("$.Key() + ':' + $.ToString('-')")
EnumerableT keySelector(T), T elementSelector(T), T resultSelector(T, Enumerable)
Enumerable.Range(1,5)
.GroupBy("$%2==0","","key,e=>key+':'+e.ToString('-')")
TK keySelector(T), TE elementSelector(T), TR resultSelector(T, Enumerable),TC compareSelector(TK)
Enumerable.From([{d:new Date(2000,1,1),i:0},{d:new Date(2000,1,1),i:1}])
.GroupBy("$.d","","key,e=>key+':'+e.Select('$.i').ToArray()","$.toString()")
PartitionByEnumerable<Grouping>T keySelector(T)
Enumerable.From([1,2,2,3,3,2,1,1]).PartitionBy("i=>i")
.Select("$.Key() + ':' + $.ToString('-')")
T keySelector(T), T elementSelector(T)
Enumerable.From([1,2,2,3,3,2,1,1]).PartitionBy("i=>i","i=>i*100")
.Select("$.Key() + ':' + $.ToString('-')")
EnumerableT keySelector(T), T elementSelector(T), T resultSelector(T, Enumerable)
Enumerable.From([1,2,2,3,3,2,1,1])
.PartitionBy("i=>i","i=>i","key,e=>key+':'+e.ToString('-')")
TK keySelector(T), TE elementSelector(T), TR resultSelector(T, Enumerable), TC compareSelector(TK)
Enumerable.From([{d:new Date(2000,1,1),i:0},{d:new Date(2000,1,1),i:1}])
.PartitionBy("$.d","","key,e=>key+':'+e.Select('$.i').ToArray()","$.toString()")
BufferWithCountEnumerable<Array>int count
Enumerable.Range(1,10).BufferWithCount(4)

Aggregate Methods

method namereturn typeargumentsexample (click code)
AggregateTT func(T, T)
Enumerable.Range(1,5).Aggregate("a,b=>a*b")
T seed, T func(T, T)
Enumerable.Range(1,10).Aggregate(100,"a,b=>a+b")
T seed, T func(T, T), T resultSelector(T)
Enumerable.Range(1,10).Aggregate(100,"a,b=>a+b","$*10")
AverageNumber()
Enumerable.Range(1,10).Average()
Number selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.Average("$.b")
CountNumber()
Enumerable.Range(1,10).Count()
bool predicate(T)
Enumerable.Range(1,10).Count("$>7")
MaxNumber()
Enumerable.Range(1,10).Max()
Number selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.Max("$.b")
MinNumber()
Enumerable.Range(1,10).Min()
Number selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.Min("$.b")
MaxByTNumber selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.MaxBy("$.b").a
MinByTNumber selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.MinBy("$.b").a
SumNumber()
Enumerable.Range(1,10).Sum()
Number selector(T)
Enumerable.From([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
.Sum("$.b")

Paging Methods

method namereturn typeargumentsexample (click code)
ElementAtTint index
Enumerable.Range(1,10).ElementAt(3)
ElementAtOrDefaultTint index, T defaultValue
Enumerable.Range(1,10).ElementAtOrDefault(15,-1)
FirstT()
Enumerable.Range(1,10).First()
bool predicate(T)
Enumerable.Range(1,10).First("$>4")
FirstOrDefaultTT defaultValue
Enumerable.Empty().FirstOrDefault(-1)
T defaultValue, bool predicate(T)
Enumerable.Range(1,10).FirstOrDefault(-1,"$>15")
LastT()
Enumerable.Range(1,10).Last()
bool predicate(T)
Enumerable.Range(1,10).Last("$<4")
LastOrDefaultTT defaultValue
Enumerable.Empty().LastOrDefault(-1)
T defaultValue, bool predicate(T)
Enumerable.Range(1,10).LastOrDefault(-1,"$>15")
SingleT()
Enumerable.From("a").Single()
bool predicate(T)
Enumerable.Range(1,10).Single("$==4")
SingleOrDefaultTT defaultValue
Enumerable.Empty().SingleOrDefault(-1)
T defaultValue, bool predicate(T)
Enumerable.Range(1,10).SingleOrDefault(-1,"$==15")
SkipEnumerableint count
Enumerable.Range(1,10).Skip(5)
SkipWhileEnumerablebool predicate(T)
Enumerable.Range(1,10).SkipWhile("$<=5")
bool predicate(T, int index)
Enumerable.Range(1,10).SkipWhile("value,index=>value+index<=5")
TakeEnumerableint count
Enumerable.Range(1,10).Take(5)
TakeWhileEnumerablebool predicate(T)
Enumerable.Range(1,10).TakeWhile("$<=5")
bool predicate(T, int index)
Enumerable.Range(1,10).TakeWhile("value,index=>value+index<=5")
TakeExceptLastEnumerable()
Enumerable.Range(1,10).TakeExceptLast()
Number count
Enumerable.Range(1,10).TakeExceptLast(3)
TakeFromLastEnumerableNumber count
Enumerable.Range(1,10).TakeFromLast(3)
IndexOfintT item
Enumerable.Range(1,10).IndexOf(3)
Enumerable.Range(1,10).IndexOf(15)
LastIndexOfintT item
Enumerable.From([1,2,3,2,5]).LastIndexOf(2)
Enumerable.From([1,2,3,2,5]).LastIndexOf(20)

Convert Methods

method namereturn typeargumentsexample (click code)
ToArrayArray()
Enumerable.Range(1,10).ToArray()
ToLookupLookupTKey keySelector(T)
var lookup = Enumerable.From(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
.ToLookup("$.match(/\\.(.+$)/)[1]");
lookup.ToEnumerable().Select("$.Key() + ' : ' + $.ToArray()")
TKey keySelector(T), TElement elementSelector(T)
var lookup = Enumerable.From(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
.ToLookup("$.match(/\\.(.+$)/)[1]","$.match(/(.+)\\.[^.]+$/)[1]");
lookup.ToEnumerable().Select("$.Key() + ' : ' + $.ToArray()")
TKey keySelector(T), TElement elementSelector(T), TCompare compareSelector(TKey)
var lookup = Enumerable.From(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
.ToLookup("","","$.match(/\\.(.+$)/)[1]");
lookup.ToEnumerable().Select("$.Key() + ' : ' + $.ToArray()")
ToObjectObjectString keySelector(T), T elementSelector(T)
var obj = Enumerable.Range(1,10).Select("value,index=>{id:'id_' + index,value:value}")
.ToObject("$.id","$.value");
Enumerable.From(obj).Select("$.Key + ':' + $.Value")
ToDictionaryDictionaryTKey keySelector(T), TElement elementSelector(T)
var dict = Enumerable.Range(1,10).Select("value,index=>{id:'id_' + index,value:value}")
.ToDictionary("$.id","$.value");
dict.ToEnumerable().Select("$.Key + ':' + $.Value")
TKey keySelector(T), TElement elementSelector(T), TCompare compareSelector(TKey)
var dict = Enumerable.Range(1,10).Select("value,index=>{id:'id_' + index,value:value}")
.ToDictionary("$","$.value","$;id");
dict.ToEnumerable().Select("$.Key.id + ':' + $.Value")
ToJSONString()
// ToJSON only work Native JSON support browser or include json2.js
Enumerable.From([{Foo:1, Bar:'z'},{Foo:5, Bar:null}]).ToJSON()
TResult replacer(TKey, TValue)
Enumerable.From(["a","b","c"])
.ToJSON(function(k,v){return (typeof v === 'object') ? v : v.toString().toUpperCase()})
TResult replacer(TKey, TValue), Number space
Enumerable.Range(1, 5).ToJSON(null, 4)
ToStringString()
Enumerable.Range(0,10).ToString()
String separator
Enumerable.Range(0,10).ToString("-")
String separator, T selector(T)
Enumerable.From([{k:"foo"},{k:"bar"}]).ToString("-","$.k")

Action Methods

method namereturn typeargumentsexample (click code)
DoEnumerablevoid action(T)
Enumerable.Range(1,10).Do(function(i){
    document.write('do:'+ i +'|');})
 .Where("$%2==0")
void action(T, index)
Enumerable.Range(1,10).Do(function(value,index){
    document.write("do:" + index + '-' + value + "<br/>");})
.OrderBy("").Take(2)
ForEachvoidvoid action(T)
Enumerable.Range(1,10).ForEach(function(i){
    document.write(i);})
void action(T, index)
Enumerable.Range(1,10).ForEach(function(value,index){
    document.write(index + ':' + value + "<br/>");})
bool func(T)
Enumerable.Range(1, 10).ForEach(function(i)
{
    if (i % 2 == 0) return; // continue
    if (i > 6) return false; // break
    document.write(i + "<br/>");
})
bool func(T, index)
Enumerable.Repeat("aaa", 10).ForEach(function(s,index)
{
    if (index % 2 == 0) return; // continue
    if (index > 6) return false; // break
    document.write(index + s + "<br/>");
})
Writevoid()
Enumerable.Range(1,10).Write()
String separator
Enumerable.Range(1,10).Write("-")
String separator, T selector(T)
Enumerable.From([{a:"foo",b:1},{a:"bar",b:3}])
.Write("-","$.a + ':' + $.b")
WriteLinevoid()
Enumerable.Range(1,10).WriteLine()
T selector(T)
Enumerable.From([{a:"foo",b:1},{a:"bar",b:3}])
.WriteLine("$.a + ':' + $.b")
Forcevoid()
Enumerable.Range(1,10).Trace().Force()

Functional Methods

method namereturn typeargumentsexample (click code)
LetEnumerableEnumerable<TR> func(Enumerable<T>)
Enumerable.Range(1,10).Let(function(x){return x.Zip(x.Skip(1),"x,y=>x + ':' + y")})
ShareEnumerable()
var share = Enumerable.Range(1,10).Share();
share.Take(4).WriteLine();
document.write("--- <br>");
share.Skip(2)
MemoizeAllEnumerable()
var mem = Enumerable.Range(1,10)
.Do("document.write('--->' + $ + '<br>')").MemoizeAll();
mem.Where("$%2==0").WriteLine();
document.write("--- <br>");
mem.Where("$%2==0")

Error Handling Methods

method namereturn typeargumentsexample (click code)
CatchEnumerablevoid handler(Error)
Enumerable.Range(1,10).Select(function(i){
    if(i == 5) throw new Error("enumerable_error"); else return i;})
.Catch("document.write($.message)")
FinallyEnumerablevoid finallyAction()
Enumerable.Range(1,5).Finally(function(){document.write("finally")})

For Debug Methods

method namereturn typeargumentsexample (click code)
TraceEnumerable()
// Trace is output to console.log
Enumerable.Range(1,10).Trace().Force()
String message
Enumerable.Range(1,10).Trace("Gen").Where("$%3==0").Trace("Filtered").Force()
String message, T selector(T)
Enumerable.From([{a:"foo",b:1},{a:"bar",b:3}])
.Trace("Gen","$.a").Force()

IEnumerator

method namereturn typeargumentsexample (click code)
GetEnumeratorIEnumerator()
Enumerable.Range(1,10).GetEnumerator()
MoveNextBoolean()
Enumerable.Range(1,10).GetEnumerator().MoveNext()
CurrentT()
Enumerable.Range(1,10).GetEnumerator().Current()
Disposevoid()
Enumerable.Range(1,10).GetEnumerator().Dispose()

Dictionary

method namereturn typeargumentsexample (click code)
AddvoidTKey key, TValue value
Enumerable.Empty().ToDictionary().Add(1, 'aaa')
GetTValueTKey key
Enumerable.Empty().ToDictionary().Get(1)
SetBooleanTKey key, TValue value
Enumerable.Empty().ToDictionary().Set(1, 'zzz')
ContainsBooleanTKey key
Enumerable.Empty().ToDictionary().Contains(1)
Clearvoid()
Enumerable.Empty().ToDictionary().Clear()
RemovevoidTKey key
Enumerable.Empty().ToDictionary().Remove(1)
CountNumber()
Enumerable.Empty().ToDictionary().Count()
ToEnumerableEnumerable()
var dict = Enumerable.Empty().ToDictionary();
dict.Add("foo", 10); dict.Add("bar", 200);
dict.ToEnumerable().Select("$.Key + ':' + $.Value")

Lookup

method namereturn typeargumentsexample (click code)
GetEnumerable<TElement>TKey key
Enumerable.From([{x:1,s:'a'},{x:1,s:'z'}])
.ToLookup("$.x").Get(1).Select("$.x + ':' + $.s")
ContainsBooleanTKey key
Enumerable.From([{x:1,s:'a'},{x:1,s:'z'}])
.ToLookup("$.x").Contains(1)
CountNumber()
Enumerable.Range(1,5).ToLookup().Count()
ToEnumerableEnumerable<Grouping>()
Enumerable.From([{a:1,s:'foo'},{a:1,s:'bar'},{a:2,s:'zzzzz'}])
.ToLookup("$.a").ToEnumerable()
.Select("$.Key() + ':' + $.Select('$.s').ToString('-')")

Grouping(inherit Eunmerable)

jQuery plugin

method namereturn typeargumentsexample (click code)
TojQueryjQuery()
// Enumerable.Repeat("foo",10).TojQuery()
toEnumerableEnumerable<jQuery>()
// $("div").toEnumerable()

RxJS Binding

method namereturn typeargumentsexample (click code)
ToObservableRx.Observable()
// Enumerable.Range(1,10).ToObservable()
ToEnumerableEnumerable()
// Rx.Observable.Range(1,10).ToEnumerable()

转载于:https://www.cnblogs.com/zcm123/p/6016976.html

 类似资料: