Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Added win32 builder

uggrock720d437aa4b2
diff --git a/build.number b/build.number
index 9b251d7b9..7ac9a873f 100644
--- a/build.number
+++ b/build.number
@@ -1,4 +1,4 @@
#Build Number for ANT. Do not edit!
-#Fri Sep 06 21:10:13 CEST 2013
-build.number=1476
+#Mon Sep 16 11:45:06 CEST 2013
+build.number=1496
3=
diff --git a/build.properties b/build.properties
index 419728491..4dd2f26ac 100644
--- a/build.properties
+++ b/build.properties
@@ -3,6 +3,10 @@ backup.dir = ../backups
builds.dir = ../builds
buildFirefoxExt.dir = ../builds/firefox
buildChrome.dir = ../builds/chrome
+buildWin32.dir = ../builds/tagspaces-win32
+buildLinux32.dir = ../builds/linux32
+buildLinux64.dir = ../builds/linux64
+buildOSX.dir = ../builds/osx
cordovaDev.dir = ../AndroidApp/www
cordovaJSLib.file = ../AndroidApp/cordova.js
tagspaces.org.release.dir = ../website/webroot/releases
\ No newline at end of file
diff --git a/build.xml b/build.xml
index 7c0a04dfe..6a248a954 100644
--- a/build.xml
+++ b/build.xml
@@ -181,6 +181,76 @@ found in the LICENSE file.
<fileset dir="${buildChrome.dir}" includes="**/*" />
</zip>
</target>
+
+ <target name="prepare-win32-package" description="copy all files for the chrome app to the build directory">
+ <buildnumber file="build.number"/>
+ <echo>Chrome directory: ${buildChrome.dir}</echo>
+ <delete dir="${buildWin32.dir}"/>
+ <mkdir dir="${buildWin32.dir}" />
+ <copy file="node-webkit/package.tmpl.json" overwrite="true" tofile="${buildWin32.dir}/package.json" />
+ <copy file="LICENSE" overwrite="true" tofile="data/LICENSE.txt" />
+ <replace file="${buildWin32.dir}/package.json" >
+ <replacefilter token="@VERSION@" value="${version}" />
+ <replacefilter token="@APPNAME@" value="${appname}" />
+ <replacefilter token="@BUILD@" value="${build.number}" />
+ </replace>
+ <copy file="data/LICENSE.txt" todir="${buildWin32.dir}" />
+ <copy file="data/index.html" todir="${buildWin32.dir}" />
+ <copy file="data/about.html" todir="${buildWin32.dir}" />
+ <copy file="data/loader.js" todir="${buildWin32.dir}" />
+ <replace file="${buildWin32.dir}/loader.js" >
+ <replacefilter token="@PRODUCTION@" value="true" />
+ </replace>
+ <copy file="node-webkit/credits.html" todir="${buildWin32.dir}" />
+ <copy file="node-webkit/nw.pak" todir="${buildWin32.dir}" />
+ <copy file="node-webkit/icudt.dll" todir="${buildWin32.dir}" />
+ <copy file="node-webkit/nw.exe" tofile="${buildWin32.dir}/tagspaces.exe" />
+ <copy todir="${buildWin32.dir}/ext" >
+ <fileset dir="data/ext">
+ <include name="perspectiveDefault/**/*"/>
+ <include name="perspectiveThumb/**/*"/>
+ <include name="perspectiveGraph/**/*"/>
+ <include name="editorHTML/**/*"/>
+ <include name="editorText/**/*"/>
+ <include name="viewerPDF/**/*"/>
+ <include name="viewerImage/**/*"/>
+ <include name="viewerMD/**/*"/>
+ </fileset>
+ </copy>
+ <copy todir="${buildWin32.dir}/libs" >
+ <fileset dir="data/libs">
+ <exclude name="less/*" />
+ <exclude name="linqjs/*" />
+ </fileset>
+ </copy>
+ <copy todir="${buildWin32.dir}/css" >
+ <fileset dir="data/css" includes="**/*"/>
+ </copy>
+ <copy todir="${buildWin32.dir}/js" >
+ <fileset dir="data/js" includes="**/*">
+ <exclude name="ioapi.cordova.js" />
+ <exclude name="ioapi.mozilla.js" />
+ <exclude name="ioapi.chrome.js" />
+ </fileset>
+ </copy>
+ <copy todir="${buildWin32.dir}/icons" >
+ <fileset dir="data/icons" includes="**/*"/>
+ </copy>
+ <replace file="${buildWin32.dir}/js/${defaultSettings.file}" >
+ <replacefilter token="@VERSION@" value="${version}" />
+ <replacefilter token="@APPNAME@" value="${appname}" />
+ <replacefilter token="@BUILD@" value="${build.number}" />
+ </replace>
+ <replace file="${buildWin32.dir}/about.html" >
+ <replacefilter token="@VERSION@" value="${version}" />
+ <replacefilter token="@APPNAME@" value="${appname}" />
+ <replacefilter token="@BUILD@" value="${build.number}" />
+ </replace>
+ </target>
+
+ <target name="build-win32-package" depends="prepare-win32-package" description="Builds win32bit package based on node-webkit">
+ <zip basedir="${builds.dir}" destfile="${builds.dir}/${appname} [v${version}.${build.number} ${DSTAMP}${TSTAMP} win32].zip" includes="tagspaces-win32/**/*" />
+ </target>
<target name="prepare-cordova-application" description="copy all files the cordova dev directory">
<!--delete dir="${cordovaDev.dir}"/>
diff --git a/data/libs/linqjs/ReadMe.txt b/data/libs/linqjs/ReadMe.txt
deleted file mode 100644
index d76dae787..000000000
--- a/data/libs/linqjs/ReadMe.txt
+++ /dev/null
@@ -1,364 +0,0 @@
-/*--------------------------------------------------------------------------
- * linq.js - LINQ for JavaScript
- * ver 3.0.4-Beta5 (Jun. 20th, 2013)
- *
- * created and maintained by neuecc <[email protected]>
- * licensed under MIT License
- * http://linqjs.codeplex.com/
- *------------------------------------------------------------------------*/
-
-2013-06-20 v3.0.4-Beta5
-add TypeScript Generic definition.
-rename linq.js.d.ts -> linq.d.ts
-add cast<T> method(for TypeScript)
-improved:cache generated string lambda function.
-
-//
-
-2012-10-09 v3.0.3-Beta4
-
-add TypeScript type declaraion file(typescript/linq.js.d.ts, linq.jquery.d.ts)
-
-//
-
-2012-09-16 s/v3.0.2-RC/v3.0.2-Beta3/::Notice
-
-fix orderByDescending to stable sort
-remove scan resultSelector overload
-rename tojQueryRaw to tojQueryAsArray
-flip argument of firstOrDefault,lastOrDefault,singleOrDefault. first is predicate, second is defaultValue.
-defaultValue of orDefault changed to null
-Enumerable.choice and Enumerable.cycle allow Enumerable
-Enumerable.from supports IIterable<T>(WinMD)
-argument of alternate allows Enumerable
-add AMD support("linqjs")
-improved fit to latest RxJS(on GitHub Sep 10, 2012 version)
-repositry convert to git
-
-//
-
-2012-07-26 v3.0.1-Beta2::Notice
-
-fix bug indexOf
-writeLine overload back to v2
-fixed bug, extendTo(Array) isn't optimized for Array
-fixed bug, defer define "enumerator" to global
-indexOf, lastIndexOf allow predicate
-changed Enumerable.from(object) enumerate only own property
-improvement all code snippets
-add isExpr to linq.qunit.js
-
-//
-
-2012-07-19 v3 Beta::Notice
-
-all methods rename UpperCamelCase to lowerCamelCase
-
-following methods are changed name
-Return -> make
-CascadeBreadthFirst -> traverseBreadthFirst
-CascadeDepthFirst -> traverseDepthFirst
-BufferWithCount -> buffer
-ToString -> toJoinedString
-Do -> doAction
-Let -> letBind
-MemoizeAll -> memoize
-Catch -> catchError
-Finally -> finallyAction
-ToJSON -> toJSONString
-
-following methods are changed behavior
-writeLine : document.write(value + "<br />") -> document.writeln(value), overload changed
-zip, concat allow multiple arguments
-
-add utility methods
-Enumerable.Utils.createLambda
-Enumerable.Utils.createEnumerable
-Enumerable.Utils.createEnumerator
-Enumerable.Utils.extendTo
-
-add enumerable methods
-Enumerable.defer
-merge
-asEnumerable
-choose
-isEmpty
-distinctUntilChanged
-weightedSample
-log
-
-performance optimization
-where->select and where->where,... and select->select,...
-range, rangeDown, rangeTo
-
-add new extension
-linq.qunit.js
-
-fix extensions to latest library version
-linq.jquery.js
-linq.rx.js
-
-removed jQuery plugin version
-
-licence changed Ms-PL to MIT
-
---
-
-//
-
-
-Features
-* implement all .NET 4.0 methods and many extra methods (inspiration from Rx, Achiral, Haskell, Ruby, etc...)
-* complete lazy evaluation
-* Full IntelliSense support for VisualStudio
-* two versions - linq.js(Normal) and jquery.linq.js(jQuery plugin)
-* support Windows Script Host
-* binding for Reactive Extensions for JavaScript(RxJS)
-* NuGet install support(linq.js, linq.js-jQuery, linq.js-Bindings)
-
-Tutorial
-
-linq.js
----
- <script type="text/javascript" src="linq.js"></script>
- <script type="text/javascript">
- // load linq.js -> Enumerable
- Enumerable.Range(1,10)....
- </script>
-
-jQuery.linq.js (jQuery plugin)
----
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="jquery.linq.js"></script>
- <script type="text/javascript">
- // load jquery.linq.js -> $.Enumerable
- $.Enumerable.Range(1,10)....
- </script>
-
- jQuery plugin version is added two methods.
- * Enumerable.prototype.TojQuery (Enumerable to jQuery object)
- * jQuery.prototype.toEnumerable (jQuery object to Eunmerable)
-
-bindings/linq.jquery.js
----
- <script type="text/javascript" src="linq.js"></script>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="linq.jquery.js"></script>
- <script type="text/javascript">
- Enumerable.Range(1,10).TojQuery()...
- </script>
-
- jQuery Bindings added two methods(TojQuery and toEnumerable)
- There are same as plugin version.
-
-binding/linq.rx.js
----
- more tutorial see linq.js CodePlex's Documentation
-
- <script type="text/javascript" src="rx.js"></script>
- <script type="text/javascript" src="linq.js"></script>
- <script type="text/javascript" src="linq.rx.js"></script>
-
- or
-
- <script type="text/javascript" src="rx.js"></script>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="jquery.linq.js"></script>
- <script type="text/javascript" src="linq.rx.js"></script>
-
--vsdoc.js
----
- Visual Studio 2010 - as is.
- Visual Studio 2008 - install SP1 and Patch KB958502.
-
- linq-vsdoc.js(or jquery.linq-vsdoc.js) puts in same directory.
-
- if not html then write xml referrence tag on top.
- for example
- /// <reference path="linq.js" />
-
-for Windows Script Host
----
- create wsf file.
- example
-
- <job id="Main">
- <script language="JScript" src="linq.js"></script>
- <script language="JScript">
- var dir = WScript.CreateObject("Scripting.FileSystemObject").GetFolder("C:\\");
-
- var itemNames = Enumerable.From(dir.SubFolders)
- .Concat(dir.Files)
- .Select("$.Name")
- .ToArray();
- </script>
- </job>
-
-How to use CodeSnippets
----
- open Visual Studio 2010's Code Snippet Manager(Ctrl+K, Ctrl+B)
- click import button and select snippets/*.snippet
-
- func0 = function () { return /*cursor*/}
- func1 = function (x) { return /*cursor*/}
- func2 = function (x, y) { return /*cursor*/}
- action0 = function () { /*cursor*/}
- action1 = function (x) { /*cursor*/}
- action2 = function (x, y) { /*cursor*/}
- efrom = Enumerable.From()
- erange = Enumerable.Range()
- jqfrom = $.Enumerable.From()
- jqrange = $.Enumerable.Range()
-
-// history
-
-2011-01-21 ver 2.2.0.2
- Add
- bindings/linq.jquery.js
- Info
- NuGet Package Added to NuGet Gallery
-
-2011-01-18 ver 2.2.0.1
- Change
- ToObservable(linq.rx.js) receive scheduler
- OrderBy optimized performance
- minifier/jQuery genereted by F# Script
- Bug Fix
- remove two not declared var
-
-2010-06-28 ver 2.2.0.0
- Add Method
- TakeFromLast
- ToJSON
- Add File
- rewrite all tests from JSUnit to QUnit
- binding for RxJS(Reactive Extensions for JavaScript)
- add RxVSDocGenerator(rx-vsdoc.js generator for RxJS)
- add code snippets for Visual Studio
- Change
- wrap array (Enumerable.From(array)) optimized performance
- Grouping optimized performance
- Enumerable.From(array)'s array allow function element
- if TakeExceptLast's count under 0 then return all sequence
- add default iterator variable's second, third, fourth($$, $$$, $$$$)
- Bug Fix
- MemoizeAll can't work when sequence contains undefined
- Sum can't work when sequence is empty(fixed return 0)
- vsdoc's Grouping elementSelector is short of summary
-
-2010-05-18 ver 2.1.0.0
- Add Class
- Dictionary
- Lookup
- Grouping
- OrderedEnumerable
-
- Add Method
- ToDictionary
- MemoizeAll
- Share
- Let
-
- Add Overload
- Join (compareKey)
- GroupJoin (compareKey)
- GroupBy (compareKey)
- PartitionBy (compareKey)
- ToLookup (compareKey)
-
- Breaking Change
- return type of ToLookup -> from Array to Lookup
- Enumerate type of GroupBy,PartitionBy -> from KeyValuePair to Grouping
-
- Change
- implimentation of OrderBy/ThenBy changed CLR compatible (maybe...)
-
- Bug Fix
- GroupBy Key auto converts to string
- All set methods do not distinction between boolean and string and number
- Scan and All Paging Methods do not work if sequence contains undefined
-
-2010-04-23 ver 2.0.0.0
- all code rewrite from scratch.
- enumerator support Dispose.
-
- namespace changed
- E, Linq.Enumerable -> Enumerable
-
- delete methods
- ToJSON
- ToTable
- TraceF
- RangeDownTo
-
- rename methods
- ZipWith -> Zip
- Slice -> BufferWithCount
- Times -> Generate
-
- change methods
- From (add argument - WSH's IEnumerable)
- Trace (write to console.log)
- RangeTo (contains downto)
- OrderBy/ThenBy (support string sort)
-
- add methods
- MaxBy
- MinBy
- OfType
- Catch
- Finally
- PartitionBy
- Alternate
- TakeExceptLast
- RepeatWithFinalize
-
- add files
- jquery.linq.js
- and minifier file by Microsoft Ajax Minifier(-HC)
-
- delete files
- linq.xml.js (move to branches)
- linq.tools.js (move to branches and rename linq.utils.js)
-
-2009-06-15 ver 1.3.0.2
- Add Make, CascadeDepthFirst/CascadeBreadthFirst.
- ForEach support continue/break.
-
-2009-06-05 ver 1.3.0.1
- IntelliSense Support.
- dom functional construction(Linq to Xml).
-
-2009-05-24 ver 1.3.0.0
- Add - Unfold, Matches, Insert, IndexOf, LastIndexOf
- Change - From<String>
- Add linq.tools.js - Stopwatch.Bench, StringBuilder.Reverse, HashSet
-
-2009-05-17 ver 1.2.0.3
- Add linq.tools.js - Stopwatch, DateUtility.IsLeapYear, DateUtility.DaysInMonth
-
-2009-05-16 ver 1.2.0.2
- Add new Sample - linq.tools.js
-
-2009-05-07 ver 1.2.0.1
- FixBug - ToJSON
- Add - Times
- Add Overload step - Range, RangeDown, RangeTo, RangeDownTo, ToInfinity, ToNegativeInfinity
-
-2009-04-26 ver 1.2.0.0
- FixBug - Set Operations(Disctint,Union,Intersect,Except)
- FixBug - ToJSON
- Add compareSelector - Contains, Distinct, Except, Intersect, SequenceEqual, Union
-
-2009-04-19 ver 1.1.0.0
- Add new Sample - linqfader
- Add linq.xml.js
-
-2009-04-10 ver 1.0.0.1
- Add - Choice
- Add - RangeTo
- Add - RangeDownTo
- Fix - Cycle
-
-2009-04-04
- 1st Release
\ No newline at end of file
diff --git a/data/libs/linqjs/linq-vsdoc.js b/data/libs/linqjs/linq-vsdoc.js
deleted file mode 100644
index 7812fa284..000000000
--- a/data/libs/linqjs/linq-vsdoc.js
+++ /dev/null
@@ -1,3656 +0,0 @@
-/*--------------------------------------------------------------------------
- * linq.js - LINQ for JavaScript
- * ver 3.0.4-Beta5 (Jun. 20th, 2013)
- *
- * created and maintained by neuecc <[email protected]>
- * licensed under MIT License
- * http://linqjs.codeplex.com/
- *------------------------------------------------------------------------*/
-
-(function (root, undefined) {
- // ReadOnly Function
- var Functions = {
- Identity: function (x) { return x; },
- True: function () { return true; },
- Blank: function () { }
- };
-
- // const Type
- var Types = {
- Boolean: typeof true,
- Number: typeof 0,
- String: typeof "",
- Object: typeof {},
- Undefined: typeof undefined,
- Function: typeof function () { }
- };
-
- // createLambda cache
- var funcCache = { "": Functions.Identity };
-
- // private utility methods
- var Utils = {
- // Create anonymous function from lambda expression string
- createLambda: function (expression) {
- if (expression == null) return Functions.Identity;
- if (typeof expression === Types.String) {
- // get from cache
- var f = funcCache[expression];
- if (f != null) {
- return f;
- }
-
- if (expression.indexOf("=>") === -1) {
- var regexp = new RegExp("[$]+", "g");
-
- var maxLength = 0;
- var match;
- while ((match = regexp.exec(expression)) != null) {
- var paramNumber = match[0].length;
- if (paramNumber > maxLength) {
- maxLength = paramNumber;
- }
- }
-
- var argArray = [];
- for (var i = 1; i <= maxLength; i++) {
- var dollar = "";
- for (var j = 0; j < i; j++) {
- dollar += "$";
- }
- argArray.push(dollar);
- }
-
- var args = Array.prototype.join.call(argArray, ",");
-
- f = new Function(args, "return " + expression);
- funcCache[expression] = f;
- return f;
- }
- else {
- var expr = expression.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);
- f = new Function(expr[1], "return " + expr[2]);
- funcCache[expression] = f;
- return f;
- }
- }
- return expression;
- },
-
- // IE8's defineProperty is defined but cannot use, therefore check defineProperties
- defineProperty: (Object.defineProperties != null)
- ? function (target, methodName, value) {
- Object.defineProperty(target, methodName, {
- enumerable: false,
- configurable: true,
- writable: true,
- value: value
- })
- }
- : function (target, methodName, value) {
- target[methodName] = value;
- },
-
- compare: function (a, b) {
- return (a === b) ? 0
- : (a > b) ? 1
- : -1;
- },
-
- dispose: function (obj) {
- if (obj != null) obj.dispose();
- }
- };
-
- // IEnumerator State
- var State = { Before: 0, Running: 1, After: 2 };
-
- // "Enumerator" is conflict JScript's "Enumerator"
- var IEnumerator = function (initialize, tryGetNext, dispose) {
- var yielder = new Yielder();
- var state = State.Before;
-
- this.current = yielder.current;
-
- this.moveNext = function () {
- /// <summary>Advances the enumerator to the next element of the collection.</summary>
- /// <returns type="Boolean"></returns>
- try {
- switch (state) {
- case State.Before:
- state = State.Running;
- initialize();
- // fall through
- case State.Running:
- if (tryGetNext.apply(yielder)) {
- return true;
- }
- else {
- this.dispose();
- return false;
- }
- case State.After:
- return false;
- }
- }
- catch (e) {
- this.dispose();
- throw e;
- }
- };
-
- this.dispose = function () {
- /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
- /// <returns type="void"></returns>
- if (state != State.Running) return;
-
- try {
- dispose();
- }
- finally {
- state = State.After;
- }
- };
- };
-
- // for tryGetNext
- var Yielder = function () {
- var current = null;
- this.current = function () {
- /// <summary>Gets the element in the collection at the current position of the enumerator.</summary>
- /// <returns type="T"></returns>
- return current;
- };
- this.yieldReturn = function (value) {
- /// <summary>Set the value to enumerator and return true.</summary>
- /// <returns type="Boolean"></returns>
- current = value;
- return true;
- };
- this.yieldBreak = function () {
- /// <summary>return false.</summary>
- /// <returns type="Boolean"></returns>
- return false;
- };
- };
-
- // Enumerable constuctor
- var Enumerable = function (getEnumerator) {
- /// <summary>Entry point of linq.js all methods.</summary>
- /// <field name="getEnumerator" type="Function">Returns an enumerator that iterates through the collection.</field>
- this.getEnumerator = getEnumerator;
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
-
- // Utility
-
- Enumerable.Utils = {}; // container
-
- Enumerable.Utils.createLambda = function (expression) {
- /// <signature>
- /// <summary>Returns the identity function such as function(x){ return x; }</summary>
- /// <param name="expression">null or undefined</param>
- /// <returns type="Function"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Returns the same function.</summary>
- /// <param name="expression" type="Function">function</param>
- /// <returns type="Function"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Make function from string.
- /// &#10;1. "" as function(x) { return x; }
- /// &#10;2. "arg1, arg2,...,=> body" as lambda expression
- /// &#10;3. "$ $$ $$$..." as lambda expression($ is default iterator variable)
- /// </summary>
- /// <param name="expression" type="String">lambda expression</param>
- /// <returns type="Function"></returns>
- /// </signature>
- /// <summary>
- /// Make function from string.
- /// &#10;1. null = function(x){ return x; }.
- /// &#10;2. Function = Function.
- /// &#10;3. "" = function(x){ return x; }.
- /// &#10;4. "arg1, arg2,...,=> body" as lambda expression
- /// &#10;5. "$ $$ $$$..." as lambda expression($ is default iterator variable)
- /// </summary>
- /// <param name="expression" type="String">lambda expression</param>
- /// <returns type="Function"></returns>
-
- return Utils.createLambda(expression);
- };
-
- Enumerable.Utils.createEnumerable = function (getEnumerator) {
- /// <summary>
- /// Create anonymous enumerable.
- /// </summary>
- /// <param name="getEnumerator" type="Func&lt;IEnumerator>">getEnumerator factory</param>
- /// <returns type="Enumerable"></returns>
- return new Enumerable(getEnumerator);
- };
-
- Enumerable.Utils.createEnumerator = function (initialize, tryGetNext, dispose) {
- /// <summary>
- /// Create anonymous enumerator.
- /// </summary>
- /// <param name="initialize" type="Action">Invoke when enumerator called moveNext at first.</param>
- /// <param name="tryGetNext" type="Action">
- /// Invoke when enumerator called moveNext.
- /// &#10;return this.yieldReturn(x); then moveNext success and set current() on x.
- /// &#10;return this.yieldBreak(); then moveNext fail.
- /// &#10;Usage: return (enumerator.moveNext()) ? this.yieldReturn(enumerator.current()) : this.yieldBreak();
- /// </param>
- /// <param name="dispose" type="Action">Invoke when enumerator called dispose.</param>
- /// <returns type="IEnumerator"></returns>
- return new IEnumerator(initialize, tryGetNext, dispose);
- };
-
- Enumerable.Utils.extendTo = function (type) {
- /// <summary>
- /// Extend all enumerable methods to prototype of type.
- /// &#10;If execution environment(e.g. browser) supports Object.defineProperty then use defineProperty and option "enumerable:false".
- /// &#10;Otherwise extends type.prototype directly.
- /// &#10;Usage: Enumerable.Utils.extendTo(Array);
- /// </summary>
- /// <param name="type" type="Constructor">Type Constructor.</param>
- /// <returns type="void"></returns>
- var typeProto = type.prototype;
- var enumerableProto;
-
- if (type === Array) {
- enumerableProto = ArrayEnumerable.prototype;
- Utils.defineProperty(typeProto, "getSource", function () {
- return this;
- });
- }
- else {
- enumerableProto = Enumerable.prototype;
- Utils.defineProperty(typeProto, "getEnumerator", function () {
- return Enumerable.from(this).getEnumerator();
- });
- }
-
- for (var methodName in enumerableProto) {
- var func = enumerableProto[methodName];
-
- // already extended
- if (typeProto[methodName] == func) continue;
-
- // already defined(example Array#reverse/join/forEach...)
- if (typeProto[methodName] != null) {
- methodName = methodName + "ByLinq";
- if (typeProto[methodName] == func) continue; // recheck
- }
-
- if (func instanceof Function) {
- Utils.defineProperty(typeProto, methodName, func);
- }
- }
- };
-
- // Generator
-
- Enumerable.choice = function (elements) // variable argument
- {
- /// <signature>
- /// <summary>
- /// Random choice from arguments.
- /// &#10;Usage: choice(1,2,3) => 1,3,2,3,3,2,1...
- /// &#10;Usage: choice([1,2,3]) => 1,3,2,3,3,2,1...
- /// </summary>
- /// <param type="params T[]" name="elements">Array or variable elements</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Random choice from arguments.
- /// &#10;Usage: choice(Enumerable.range(1,3)) => 1,3,2,3,3,2,1...
- /// </summary>
- /// <param type="Enumerable" name="elements">Enumerable elements</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>
- /// Random choice from arguments.
- /// &#10;Usage: choice(1,2,3) => 1,3,2,3,3,2,1...
- /// &#10;Usage: choice([1,2,3]) => 1,3,2,3,3,2,1...
- /// </summary>
- /// <param type="params T[]" name="elements">Array or Enumerable or variable elements</param>
- /// <returns type="Enumerable"></returns>
- var args = arguments;
-
- return new Enumerable(function () {
- return new IEnumerator(
- function () {
- args = (args[0] instanceof Array) ? args[0]
- : (args[0].getEnumerator != null) ? args[0].toArray()
- : args;
- },
- function () {
- return this.yieldReturn(args[Math.floor(Math.random() * args.length)]);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.cycle = function (elements) // variable argument
- {
- /// <signature>
- /// <summary>
- /// Cycle repeat from arguments.
- /// &#10;Usage: cycle(1,2,3) => 1,2,3,1,2,3,1,2,3...
- /// &#10;Usage: cycle([1,2,3]) => 1,2,3,1,2,3,1,2,3...
- /// </summary>
- /// <param type="params T[]" name="elements">Array or variable elements</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Cycle repeat from arguments.
- /// &#10;Usage: cycle(Enumerable.range(1,3)) => 1,2,3,1,2,3,1,2,3...
- /// </summary>
- /// <param type="Enumerable" name="elements">Enumerable elements</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>
- /// Cycle repeat from arguments.
- /// &#10;Usage: cycle(1,2,3) => 1,2,3,1,2,3,1,2,3...
- /// &#10;Usage: cycle([1,2,3]) => 1,2,3,1,2,3,1,2,3...
- /// </summary>
- /// <param type="params T[]" name="elements">Array or Enumerable or variable elements</param>
- /// <returns type="Enumerable"></returns>
- var args = arguments;
-
- return new Enumerable(function () {
- var index = 0;
- return new IEnumerator(
- function () {
- args = (args[0] instanceof Array) ? args[0]
- : (args[0].getEnumerator != null) ? args[0].toArray()
- : args;
- },
- function () {
- if (index >= args.length) index = 0;
- return this.yieldReturn(args[index++]);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.empty = function () {
- /// <summary>Returns an empty Enumerable.</summary>
- /// <returns type="Enumerable"></returns>
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return false; },
- Functions.Blank);
- });
- };
-
- Enumerable.from = function (obj) {
- /// <signature>
- /// <summary>Make empty enumerable from null or undefined.</summary>
- /// <param name="blankObject">null or undefined</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Returns the same object.</summary>
- /// <param name="enumerable" type="Enumerable">Enumerable object</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Make the single enumerable.</summary>
- /// <param name="number" type="Number">Number primitive</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Make the single enumerable.</summary>
- /// <param name="boolean" type="Boolean">Boolean primitive</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Make charactor sequence.
- /// &#10;Usage: "abc" => "a", "b", "c"
- /// </summary>
- /// <param name="str" type="String">String primitive</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Make own property to KeyValuePair sequence.
- /// &#10;Usage: "{a:0}" => (.key = "a", .value = 0).
- /// </summary>
- /// <param name="obj" type="Object">JavaScript object</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Make Enumerable sequence.</summary>
- /// <param name="array" type="Array">Array or ArrayLikeObject(has length)</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Make Enumerable using JScript's Enumerator.</summary>
- /// <param name="ienumerable">JScript's IEnumerable</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Make Enumerable using IIterator&lt;T&gt;.</summary>
- /// <param name="iiterable">WinMD's IIterable&lt;T&gt;</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>
- /// Make Enumerable from obj.
- /// &#10;1. null = Enumerable.empty().
- /// &#10;2. Enumerable = Enumerable.
- /// &#10;3. Number/Boolean = Enumerable.repeat(obj, 1).
- /// &#10;4. String = to CharArray. Usage: "abc" => "a","b","c").
- /// &#10;5. Object/Function = own property to KeyValuePairs. Usage: "{a:0}" => (.key = "a", .value = 0).
- /// &#10;6. Array or ArrayLikeObject(has length) = to Enumerable.
- /// &#10;7. JScript's IEnumerable = to Enumerable(using Enumerator).
- /// &#10;8. WinMD's IIterable&lt;T&gt; = to Enumerable(using IIterator&lt;T&gt;).
- /// </summary>
- /// <param name="obj">object</param>
- /// <returns type="Enumerable"></returns>
-
- if (obj == null) {
- return Enumerable.empty();
- }
- if (obj instanceof Enumerable) {
- return obj;
- }
- if (typeof obj == Types.Number || typeof obj == Types.Boolean) {
- return Enumerable.repeat(obj, 1);
- }
- if (typeof obj == Types.String) {
- return new Enumerable(function () {
- var index = 0;
- return new IEnumerator(
- Functions.Blank,
- function () {
- return (index < obj.length) ? this.yieldReturn(obj.charAt(index++)) : false;
- },
- Functions.Blank);
- });
- }
- if (typeof obj != Types.Function) {
- // array or array like object
- if (typeof obj.length == Types.Number) {
- return new ArrayEnumerable(obj);
- }
-
- // JScript's IEnumerable
- if (!(obj instanceof Object) && Utils.isIEnumerable(obj)) {
- return new Enumerable(function () {
- var isFirst = true;
- var enumerator;
- return new IEnumerator(
- function () { enumerator = new Enumerator(obj); },
- function () {
- if (isFirst) isFirst = false;
- else enumerator.moveNext();
-
- return (enumerator.atEnd()) ? false : this.yieldReturn(enumerator.item());
- },
- Functions.Blank);
- });
- }
-
- // WinMD IIterable<T>
- if (typeof Windows === Types.Object && typeof obj.first === Types.Function) {
- return new Enumerable(function () {
- var isFirst = true;
- var enumerator;
- return new IEnumerator(
- function () { enumerator = obj.first(); },
- function () {
- if (isFirst) isFirst = false;
- else enumerator.moveNext();
-
- return (enumerator.hasCurrent) ? this.yieldReturn(enumerator.current) : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- }
-
- // case function/object : Create keyValuePair[]
- return new Enumerable(function () {
- var array = [];
- var index = 0;
-
- return new IEnumerator(
- function () {
- for (var key in obj) {
- var value = obj[key];
- if (!(value instanceof Function) && Object.prototype.hasOwnProperty.call(obj, key)) {
- array.push({ key: key, value: value });
- }
- }
- },
- function () {
- return (index < array.length)
- ? this.yieldReturn(array[index++])
- : false;
- },
- Functions.Blank);
- });
- },
-
- Enumerable.make = function (element) {
- /// <summary>Make one sequence. This equals repeat(element, 1)</summary>
- /// <param name="element" type="T">element</param>
- /// <returns type="Enumerable"></returns>
- return Enumerable.repeat(element, 1);
- };
-
- Enumerable.matches = function (input, pattern, flags) {
- /// <summary>
- /// Global regex match and send regexp object.
- /// &#10;Usage: matches((.)z,"0z1z2z") => $[1] = 0,1,2
- /// </summary>
- /// <param type="String" name="input">input string</param>
- /// <param type="RegExp/String" name="pattern">RegExp or Pattern string</param>
- /// <param type="String" name="flags" optional="true">If pattern is String then can use regexp flags "i"(ignoreCase) or "m"(multiLine) or "im"(both)</param>
- /// <returns type="Enumerable"></returns>
- if (flags == null) flags = "";
- if (pattern instanceof RegExp) {
- flags += (pattern.ignoreCase) ? "i" : "";
- flags += (pattern.multiline) ? "m" : "";
- pattern = pattern.source;
- }
- if (flags.indexOf("g") === -1) flags += "g";
-
- return new Enumerable(function () {
- var regex;
- return new IEnumerator(
- function () { regex = new RegExp(pattern, flags); },
- function () {
- var match = regex.exec(input);
- return (match) ? this.yieldReturn(match) : false;
- },
- Functions.Blank);
- });
- };
-
- Enumerable.range = function (start, count, step) {
- /// <summary>
- /// Generates a sequence of integral numbers within a specified range.
- /// &#10;Usage: range(1,5) => 1,2,3,4,5
- /// </summary>
- /// <param type="Number" integer="true" name="start">The value of the first integer in the sequence.</param>
- /// <param type="Number" integer="true" name="count">The number of sequential integers to generate.</param>
- /// <param type="Number" integer="true" name="step" optional="true">Step of generate number. Usage: range(0,3,5) => 0,5,10</param>
- /// <returns type="Enumerable"></returns>
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- var index = 0;
-
- return new IEnumerator(
- function () { value = start - step; },
- function () {
- return (index++ < count)
- ? this.yieldReturn(value += step)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- Enumerable.rangeDown = function (start, count, step) {
- /// <summary>
- /// Generates a sequence of integral numbers within a specified range.
- /// &#10;Usage: rangeDown(5,5) => 5,4,3,2,1
- /// </summary>
- /// <param type="Number" integer="true" name="start">The value of the first integer in the sequence.</param>
- /// <param type="Number" integer="true" name="count">The number of sequential integers to generate.</param>
- /// <param type="Number" integer="true" name="step" optional="true">Step of generate number. Usage: rangeDown(0,3,5) => 0,-5,-10</param>
- /// <returns type="Enumerable"></returns>
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- var index = 0;
-
- return new IEnumerator(
- function () { value = start + step; },
- function () {
- return (index++ < count)
- ? this.yieldReturn(value -= step)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- Enumerable.rangeTo = function (start, to, step) {
- /// <summary>Generates a sequence of integral numbers.
- /// &#10;Usage: rangeTo(10, 12) => 10,11,12 | rangeTo(0, -2) => 0, -1, -2</summary>
- /// <param type="Number" integer="true" name="start">start integer</param>
- /// <param type="Number" integer="true" name="to">to integer</param>
- /// <param type="Number" integer="true" name="step" optional="true">Step of generate number. Usage: rangeTo(0, 7, 3) => 0,3,6</param>
- /// <returns type="Enumerable"></returns>
-
- if (step == null) step = 1;
-
- if (start < to) {
- return new Enumerable(function () {
- var value;
-
- return new IEnumerator(
- function () { value = start - step; },
- function () {
- var next = value += step;
- return (next <= to)
- ? this.yieldReturn(next)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- else {
- return new Enumerable(function () {
- var value;
-
- return new IEnumerator(
- function () { value = start + step; },
- function () {
- var next = value -= step;
- return (next >= to)
- ? this.yieldReturn(next)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- };
-
- Enumerable.repeat = function (element, count) {
- /// <summary>
- /// Generates a sequence that contains one repeated value.
- /// &#10;If omit count then generate to infinity.
- /// &#10;Usage: repeat("foo", 3) => "foo","foo","foo"
- /// </summary>
- /// <param type="T" name="element">The value to be repeated.</param>
- /// <param type="Number" integer="true" name="count" optional="true">The number of times to repeat the value in the generated sequence.</param>
- /// <returns type="Enumerable"></returns>
- if (count != null) return Enumerable.repeat(element).take(count);
-
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return this.yieldReturn(element); },
- Functions.Blank);
- });
- };
-
- Enumerable.repeatWithFinalize = function (initializer, finalizer) {
- /// <summary>Lazy Generates one value by initializer's result and do finalize when enumerate end.</summary>
- /// <param type="Func&lt;T>" name="initializer">value factory.</param>
- /// <param type="Action&lt;T>" name="finalizer">execute when finalize.</param>
- /// <returns type="Enumerable"></returns>
- initializer = Utils.createLambda(initializer);
- finalizer = Utils.createLambda(finalizer);
-
- return new Enumerable(function () {
- var element;
- return new IEnumerator(
- function () { element = initializer(); },
- function () { return this.yieldReturn(element); },
- function () {
- if (element != null) {
- finalizer(element);
- element = null;
- }
- });
- });
- };
-
- Enumerable.generate = function (func, count) {
- /// <summary>
- /// Generates a sequence that execute func value.
- /// &#10;If omit count then generate to infinity.
- /// &#10;Usage: generate("Math.random()", 5) => 0.131341,0.95425252,...
- /// </summary>
- /// <param type="Func&lt;T>" name="func">The value of execute func to be repeated.</param>
- /// <param type="Number" integer="true" name="count" optional="true">The number of times to repeat the value in the generated sequence.</param>
- /// <returns type="Enumerable"></returns>
- if (count != null) return Enumerable.generate(func).take(count);
- func = Utils.createLambda(func);
-
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return this.yieldReturn(func()); },
- Functions.Blank);
- });
- };
-
- Enumerable.toInfinity = function (start, step) {
- /// <summary>
- /// Generates a sequence of integral numbers to infinity.
- /// &#10;Usage: toInfinity() => 0,1,2,3...
- /// </summary>
- /// <param type="Number" integer="true" name="start" optional="true">start integer.</param>
- /// <param type="Number" integer="true" name="step" optional="true">Step of generate number. Usage: toInfinity(10,3) => 10,13,16,19,...</param>
- /// <returns type="Enumerable"></returns>
- if (start == null) start = 0;
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- return new IEnumerator(
- function () { value = start - step; },
- function () { return this.yieldReturn(value += step); },
- Functions.Blank);
- });
- };
-
- Enumerable.toNegativeInfinity = function (start, step) {
- /// <summary>
- /// Generates a sequence of integral numbers to negative infinity.
- /// &#10;Usage: toNegativeInfinity() => 0,-1,-2,-3...
- /// </summary>
- /// <param type="Number" integer="true" name="start" optional="true">start integer.</param>
- /// <param type="Number" integer="true" name="step" optional="true">Step of generate number. Usage: toNegativeInfinity(10,3) => 10,7,4,1,...</param>
- /// <returns type="Enumerable"></returns>
- if (start == null) start = 0;
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- return new IEnumerator(
- function () { value = start + step; },
- function () { return this.yieldReturn(value -= step); },
- Functions.Blank);
- });
- };
-
- Enumerable.unfold = function (seed, func) {
- /// <summary>
- /// Applies function and generates a infinity sequence.
- /// &#10;Usage: unfold(3, "$+10") => 3,13,23,...</summary>
- /// <param type="T" name="seed">The initial accumulator value.</param>
- /// <param type="Func&lt;T,T>" name="func">An accumulator function to be invoked on each element.</param>
- /// <returns type="Enumerable"></returns>
- func = Utils.createLambda(func);
-
- return new Enumerable(function () {
- var isFirst = true;
- var value;
- return new IEnumerator(
- Functions.Blank,
- function () {
- if (isFirst) {
- isFirst = false;
- value = seed;
- return this.yieldReturn(value);
- }
- value = func(value);
- return this.yieldReturn(value);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.defer = function (enumerableFactory) {
- /// <summary>
- /// Make enumerable enumerableFactory as need.
- /// &#10;Usage: defer(function(){ return [1,2,3] })</summary>
- /// <param type="Function" name="enumerableFactory">Enumerable factory, function returns array or enumerable.</param>
- /// <returns type="Enumerable"></returns>
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = Enumerable.from(enumerableFactory()).getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : this.yieldBreak();
- },
- function () {
- Utils.dispose(enumerator);
- });
- });
- };
-
- // Extension Methods
-
- /* Projection and Filtering Methods */
-
- Enumerable.prototype.traverseBreadthFirst = function (func, resultSelector) {
- /// <summary>Projects each element of sequence and flattens the resulting sequences into one sequence use breadth first search.</summary>
- /// <param name="func" type="Func&lt;TSource,Enumerable&lt;TCollection>>">Select child sequence.</param>
- /// <param name="resultSelector" type="Func&lt;TCollection,int,TResult>" optional="true">A transform function to apply to each element of the intermediate sequence.; Optional:the second parameter of the function represents the nestlevel of the source element.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- func = Utils.createLambda(func);
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumerator;
- var nestLevel = 0;
- var buffer = [];
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (enumerator.moveNext()) {
- buffer.push(enumerator.current());
- return this.yieldReturn(resultSelector(enumerator.current(), nestLevel));
- }
-
- var next = Enumerable.from(buffer).selectMany(function (x) { return func(x); });
- if (!next.any()) {
- return false;
- }
- else {
- nestLevel++;
- buffer = [];
- Utils.dispose(enumerator);
- enumerator = next.getEnumerator();
- }
- }
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.traverseDepthFirst = function (func, resultSelector) {
- /// <summary>Projects each element of sequence and flattens the resulting sequences into one sequence use depth first search.</summary>
- /// <param name="func" type="Func&lt;TSource,Enumerable&lt;TCollection>>">Select child sequence.</param>
- /// <param name="resultSelector" type="Func&lt;TCollection,int,TResult>" optional="true">A transform function to apply to each element of the intermediate sequence.; Optional:the second parameter of the function represents the nestlevel of the source element.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- func = Utils.createLambda(func);
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumeratorStack = [];
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (enumerator.moveNext()) {
- var value = resultSelector(enumerator.current(), enumeratorStack.length);
- enumeratorStack.push(enumerator);
- enumerator = Enumerable.from(func(enumerator.current())).getEnumerator();
- return this.yieldReturn(value);
- }
-
- if (enumeratorStack.length <= 0) return false;
- Utils.dispose(enumerator);
- enumerator = enumeratorStack.pop();
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Enumerable.from(enumeratorStack).forEach(function (s) { s.dispose(); });
- }
- });
- });
- };
-
- Enumerable.prototype.flatten = function () {
- /// <summary>Flatten sequences into one sequence.</summary>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var middleEnumerator = null;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (middleEnumerator != null) {
- if (middleEnumerator.moveNext()) {
- return this.yieldReturn(middleEnumerator.current());
- }
- else {
- middleEnumerator = null;
- }
- }
-
- if (enumerator.moveNext()) {
- if (enumerator.current() instanceof Array) {
- Utils.dispose(middleEnumerator);
- middleEnumerator = Enumerable.from(enumerator.current())
- .selectMany(Functions.Identity)
- .flatten()
- .getEnumerator();
- continue;
- }
- else {
- return this.yieldReturn(enumerator.current());
- }
- }
-
- return false;
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(middleEnumerator);
- }
- });
- });
- };
-
- Enumerable.prototype.pairwise = function (selector) {
- /// <summary>Projects current and next element of a sequence into a new form.</summary>
- /// <param type="Func&lt;TSource,TSource,TResult>" name="selector">A transform function to apply to current and next element.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- selector = Utils.createLambda(selector);
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- enumerator.moveNext();
- },
- function () {
- var prev = enumerator.current();
- return (enumerator.moveNext())
- ? this.yieldReturn(selector(prev, enumerator.current()))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.scan = function (seed, func) {
- /// <signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="func" type="Func&lt;TSource,TSource,TSource>">An accumulator function to be invoked on each element.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="seed" type="TAccumulate">the initial accumulator value.</param>
- /// <param name="func" type="Func&lt;TAccumulate,TSource,TAccumulate>">An accumulator function to be invoked on each element.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="seed" type="Func&lt;T,T,T>_or_TAccumulate">Func is an accumulator function to be invoked on each element. Seed is the initial accumulator value.</param>
- /// <param name="func" type="Optional:Func&lt;TAccumulate,T,TAccumulate>" optional="true">An accumulator function to be invoked on each element.</param>
- /// <returns type="Enumerable"></returns>
- var isUseSeed;
- if (func == null) {
- func = Utils.createLambda(seed); // arguments[0]
- isUseSeed = false;
- }
- else {
- func = Utils.createLambda(func);
- isUseSeed = true;
- }
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var value;
- var isFirst = true;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (isFirst) {
- isFirst = false;
- if (!isUseSeed) {
- if (enumerator.moveNext()) {
- return this.yieldReturn(value = enumerator.current());
- }
- }
- else {
- return this.yieldReturn(value = seed);
- }
- }
-
- return (enumerator.moveNext())
- ? this.yieldReturn(value = func(value, enumerator.current()))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(selector<element>)
- // Overload:function(selector<element,index>)
- Enumerable.prototype.select = function (selector) {
- /// <summary>Projects each element of a sequence into a new form.</summary>
- /// <param name="selector" type="Func&lt;T,int,T>">A transform function to apply to each source element; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- selector = Utils.createLambda(selector);
-
- if (selector.length <= 1) {
- return new WhereSelectEnumerable(this, null, selector);
- }
- else {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(selector(enumerator.current(), index++))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- }
- };
-
- // Overload:function(collectionSelector<element>)
- // Overload:function(collectionSelector<element,index>)
- // Overload:function(collectionSelector<element>,resultSelector)
- // Overload:function(collectionSelector<element,index>,resultSelector)
- Enumerable.prototype.selectMany = function (collectionSelector, resultSelector) {
- /// <summary>Projects each element of a sequence and flattens the resulting sequences into one sequence.</summary>
- /// <param name="collectionSelector" type="Func&lt;T,int,TCollection[]>">A transform function to apply to each source element; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <param name="resultSelector" type="Func&lt;T,TCollection,TResult>" optional="true">A transform function to apply to each element of the intermediate sequence.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- collectionSelector = Utils.createLambda(collectionSelector);
- if (resultSelector == null) resultSelector = function (a, b) { return b; };
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumerator;
- var middleEnumerator = undefined;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (middleEnumerator === undefined) {
- if (!enumerator.moveNext()) return false;
- }
- do {
- if (middleEnumerator == null) {
- var middleSeq = collectionSelector(enumerator.current(), index++);
- middleEnumerator = Enumerable.from(middleSeq).getEnumerator();
- }
- if (middleEnumerator.moveNext()) {
- return this.yieldReturn(resultSelector(enumerator.current(), middleEnumerator.current()));
- }
- Utils.dispose(middleEnumerator);
- middleEnumerator = null;
- } while (enumerator.moveNext());
- return false;
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(middleEnumerator);
- }
- });
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.where = function (predicate) {
- /// <summary>Filters a sequence of values based on a predicate.</summary>
- /// <param name="predicate" type="Func&lt;T,int,bool>">A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- predicate = Utils.createLambda(predicate);
-
- if (predicate.length <= 1) {
- return new WhereEnumerable(this, predicate);
- }
- else {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate(enumerator.current(), index++)) {
- return this.yieldReturn(enumerator.current());
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- }
- };
-
- // Overload:function(selector<element>)
- // Overload:function(selector<element,index>)
- Enumerable.prototype.choose = function (selector) {
- /// <summary>Projection and filter if projected value is null or undefined.</summary>
- /// <param name="selector" type="Func&lt;T,int,TR>">A transform function; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- selector = Utils.createLambda(selector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- var result = selector(enumerator.current(), index++);
- if (result != null) {
- return this.yieldReturn(result);
- }
- }
- return this.yieldBreak();
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.ofType = function (type) {
- /// <summary>Filters the elements based on a specified type.</summary>
- /// <param name="type" type="T">The type to filter the elements of the sequence on.</param>
- /// <returns type="Enumerable"></returns>
- var typeName;
- switch (type) {
- case Number:
- typeName = Types.Number;
- break;
- case String:
- typeName = Types.String;
- break;
- case Boolean:
- typeName = Types.Boolean;
- break;
- case Function:
- typeName = Types.Function;
- break;
- default:
- typeName = null;
- break;
- }
- return (typeName === null)
- ? this.where(function (x) { return x instanceof type; })
- : this.where(function (x) { return typeof x === typeName; });
- };
-
- // mutiple arguments, last one is selector, others are enumerable
- Enumerable.prototype.zip = function (_elements, _selector) {
- /// <signature>
- /// <summary>Merges many sequences by using the specified selector. The last argument is selector.</summary>
- /// <param type="params Enumerable&lt;T>[]" name="elements">The multiple sequence to merge.</param>
- /// <param name="selector" type="Func&lt;TFirst,TSecond,TThird,...,int,TResult>">A function that specifies how to merge the elements from the many sequences. Optional:the last parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>Merges many sequences by using the specified selector. The last argument is selector.</summary>
- /// <param type="params_Enumerable&lt;T>" name="_elements">The multiple sequence to merge.</param>
- /// <param name="_selector" type="Func&lt;TFirst,TSecond,TThird,...,int,TResult>">A function that specifies how to merge the elements from the many sequences. Optional:the last parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- var args = arguments;
- var selector = Utils.createLambda(arguments[arguments.length - 1]);
-
- var source = this;
- // optimized case:argument is 2
- if (arguments.length == 2) {
- var second = arguments[0];
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var index = 0;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- secondEnumerator = Enumerable.from(second).getEnumerator();
- },
- function () {
- if (firstEnumerator.moveNext() && secondEnumerator.moveNext()) {
- return this.yieldReturn(selector(firstEnumerator.current(), secondEnumerator.current(), index++));
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- } finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- }
- else {
- return new Enumerable(function () {
- var enumerators;
- var index = 0;
-
- return new IEnumerator(
- function () {
- var array = Enumerable.make(source)
- .concat(Enumerable.from(args).takeExceptLast().select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- enumerators = Enumerable.from(array);
- },
- function () {
- if (enumerators.all(function (x) { return x.moveNext() })) {
- var array = enumerators
- .select(function (x) { return x.current() })
- .toArray();
- array.push(index++);
- return this.yieldReturn(selector.apply(null, array));
- }
- else {
- return this.yieldBreak();
- }
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- }
- };
-
- // mutiple arguments
- Enumerable.prototype.merge = function (_elements) {
- /// <signature>
- /// <summary>
- /// Merges many sequences in turn. Target sequence is variable.
- /// &#10;Usage: seqX.merge(seqY, seqZ) => [x, y, z, x, y, z, x, y,....]
- /// </summary>
- /// <param type="params Enumerable&lt;T>[]" name="elements">The multiple sequence to merge.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>
- /// Merges many sequences in turn. Target sequence is variable.
- /// &#10;Usage: seqX.merge(seqY, seqZ) => [x, y, z, x, y, z, x, y,....]
- /// </summary>
- /// <param type="params_Enumerable&lt;T>" name="_elements">The multiple sequence to merge.</param>
- /// <returns type="Enumerable"></returns>
- var args = arguments;
- var source = this;
-
- return new Enumerable(function () {
- var enumerators;
- var index = -1;
-
- return new IEnumerator(
- function () {
- enumerators = Enumerable.make(source)
- .concat(Enumerable.from(args).select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- },
- function () {
- while (enumerators.length > 0) {
- index = (index >= enumerators.length - 1) ? 0 : index + 1;
- var enumerator = enumerators[index];
-
- if (enumerator.moveNext()) {
- return this.yieldReturn(enumerator.current());
- }
- else {
- enumerator.dispose();
- enumerators.splice(index--, 1);
- }
- }
- return this.yieldBreak();
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- };
-
- /* Join Methods */
-
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector)
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector)
- Enumerable.prototype.join = function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
- /// <summary>Correlates the elements of two sequences based on matching keys.</summary>
- /// <param name="inner" type="Enumerable&lt;T>">The sequence to join to the first sequence.</param>
- /// <param name="outerKeySelector" type="Func&lt;TOuter,TKey>">A function to extract the join key from each element of the first sequence.</param>
- /// <param name="innerKeySelector" type="Func&lt;TInner,TKey>">A function to extract the join key from each element of the second sequence.</param>
- /// <param name="resultSelector" type="Func&lt;TOuter,TInner,TResult>">A function to create a result element from two matching elements.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- outerKeySelector = Utils.createLambda(outerKeySelector);
- innerKeySelector = Utils.createLambda(innerKeySelector);
- resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var outerEnumerator;
- var lookup;
- var innerElements = null;
- var innerCount = 0;
-
- return new IEnumerator(
- function () {
- outerEnumerator = source.getEnumerator();
- lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
- },
- function () {
- while (true) {
- if (innerElements != null) {
- var innerElement = innerElements[innerCount++];
- if (innerElement !== undefined) {
- return this.yieldReturn(resultSelector(outerEnumerator.current(), innerElement));
- }
-
- innerElement = null;
- innerCount = 0;
- }
-
- if (outerEnumerator.moveNext()) {
- var key = outerKeySelector(outerEnumerator.current());
- innerElements = lookup.get(key).toArray();
- } else {
- return false;
- }
- }
- },
- function () { Utils.dispose(outerEnumerator); });
- });
- };
-
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector)
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector)
- Enumerable.prototype.groupJoin = function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
- /// <summary>Correlates the elements of two sequences based on equality of keys and groups the results.</summary>
- /// <param name="inner" type="T[]">The sequence to join to the first sequence.</param>
- /// <param name="outerKeySelector" type="Func&lt;TOuter>">A function to extract the join key from each element of the first sequence.</param>
- /// <param name="innerKeySelector" type="Func&lt;TInner>">A function to extract the join key from each element of the second sequence.</param>
- /// <param name="resultSelector" type="Func&lt;TOuter,Enumerable&lt;TInner>,TResult">A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- outerKeySelector = Utils.createLambda(outerKeySelector);
- innerKeySelector = Utils.createLambda(innerKeySelector);
- resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator = source.getEnumerator();
- var lookup = null;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
- },
- function () {
- if (enumerator.moveNext()) {
- var innerElement = lookup.get(outerKeySelector(enumerator.current()));
- return this.yieldReturn(resultSelector(enumerator.current(), innerElement));
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- /* Set Methods */
-
- Enumerable.prototype.all = function (predicate) {
- /// <summary>Determines whether all elements of a sequence satisfy a condition.</summary>
- /// <param type="Func&lt;T,bool>" name="predicate">A function to test each element for a condition.</param>
- /// <returns type="Boolean"></returns>
- predicate = Utils.createLambda(predicate);
-
- var result = true;
- this.forEach(function (x) {
- if (!predicate(x)) {
- result = false;
- return false; // break
- }
- });
- return result;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.any = function (predicate) {
- /// <summary>Determines whether a sequence contains any elements or any element of a sequence satisfies a condition.</summary>
- /// <param name="predicate" type="Func&lt;T,bool>" optional="true">A function to test each element for a condition.</param>
- /// <returns type="Boolean"></returns>
- predicate = Utils.createLambda(predicate);
-
- var enumerator = this.getEnumerator();
- try {
- if (arguments.length == 0) return enumerator.moveNext(); // case:function()
-
- while (enumerator.moveNext()) // case:function(predicate)
- {
- if (predicate(enumerator.current())) return true;
- }
- return false;
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- Enumerable.prototype.isEmpty = function () {
- /// <summary>Check the Sequence is empty.</summary>
- /// <returns type="Boolean"></returns>
- return !this.any();
- };
-
- // multiple arguments
- Enumerable.prototype.concat = function (_elements) {
- /// <signature>
- /// <summary>Concatenates many sequences.</summary>
- /// <param name="elements" type="params Enumerable&lt;T>[]">The sequences to concatenate to the first sequence.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>Concatenates many sequences.</summary>
- /// <param name="_elements" type="params_Enumerable&lt;T>[]">The sequences to concatenate to the first sequence.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- if (arguments.length == 1) {
- var second = arguments[0];
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
-
- return new IEnumerator(
- function () { firstEnumerator = source.getEnumerator(); },
- function () {
- if (secondEnumerator == null) {
- if (firstEnumerator.moveNext()) return this.yieldReturn(firstEnumerator.current());
- secondEnumerator = Enumerable.from(second).getEnumerator();
- }
- if (secondEnumerator.moveNext()) return this.yieldReturn(secondEnumerator.current());
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- }
- else {
- var args = arguments;
-
- return new Enumerable(function () {
- var enumerators;
-
- return new IEnumerator(
- function () {
- enumerators = Enumerable.make(source)
- .concat(Enumerable.from(args).select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- },
- function () {
- while (enumerators.length > 0) {
- var enumerator = enumerators[0];
-
- if (enumerator.moveNext()) {
- return this.yieldReturn(enumerator.current());
- }
- else {
- enumerator.dispose();
- enumerators.splice(0, 1);
- }
- }
- return this.yieldBreak();
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- }
- };
-
- Enumerable.prototype.insert = function (index, second) {
- /// <summary>Merge two sequences.</summary>
- /// <param name="index" type="Number" integer="true">The index of insert start position.</param>
- /// <param name="second" type="Enumerable&lt;T>">The sequence to concatenate to the first sequence.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var count = 0;
- var isEnumerated = false;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- secondEnumerator = Enumerable.from(second).getEnumerator();
- },
- function () {
- if (count == index && secondEnumerator.moveNext()) {
- isEnumerated = true;
- return this.yieldReturn(secondEnumerator.current());
- }
- if (firstEnumerator.moveNext()) {
- count++;
- return this.yieldReturn(firstEnumerator.current());
- }
- if (!isEnumerated && secondEnumerator.moveNext()) {
- return this.yieldReturn(secondEnumerator.current());
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- };
-
- Enumerable.prototype.alternate = function (alternateValueOrSequence) {
- /// <signature>
- /// <summary>
- /// Insert value to between sequence.
- /// &#10;Usage: [1,2,3].alternate(0) => 1,0,2,0,3
- /// </summary>
- /// <param name="alternateValue" type="T">The value of insert.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <signature>
- /// <summary>
- /// Insert value to between sequence.
- /// &#10;Usage: [1,2,3].alternate([-1,-2]) => 1,-1,-2,2,-1,-2,3
- /// </summary>
- /// <param name="alternateSequence" type="Enumerable&lt;T>">The values of insert.</param>
- /// <returns type="Enumerable"></returns>
- /// </signature>
- /// <summary>
- /// Insert value to between sequence.
- /// &#10;Usage: [1,2,3].alternate(0) => 1,0,2,0,3
- /// &#10;Usage: [1,2,3].alternate([-1,-2]) => 1,-1,-2,2,-1,-2,3
- /// </summary>
- /// <param name="alternateValueOrSequence" type="T_or_Enumerable&lt;T>">The value(or values) of insert.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
- var enumerator;
- var alternateSequence;
- var alternateEnumerator;
-
- return new IEnumerator(
- function () {
- if (alternateValueOrSequence instanceof Array || alternateValueOrSequence.getEnumerator != null) {
- alternateSequence = Enumerable.from(Enumerable.from(alternateValueOrSequence).toArray()); // freeze
- }
- else {
- alternateSequence = Enumerable.make(alternateValueOrSequence);
- }
- enumerator = source.getEnumerator();
- if (enumerator.moveNext()) buffer = enumerator.current();
- },
- function () {
- while (true) {
- if (alternateEnumerator != null) {
- if (alternateEnumerator.moveNext()) {
- return this.yieldReturn(alternateEnumerator.current());
- }
- else {
- alternateEnumerator = null;
- }
- }
-
- if (buffer == null && enumerator.moveNext()) {
- buffer = enumerator.current(); // hasNext
- alternateEnumerator = alternateSequence.getEnumerator();
- continue; // GOTO
- }
- else if (buffer != null) {
- var retVal = buffer;
- buffer = null;
- return this.yieldReturn(retVal);
- }
-
- return this.yieldBreak();
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(alternateEnumerator);
- }
- });
- });
- };
-
- // Overload:function(value)
- // Overload:function(value, compareSelector)
- Enumerable.prototype.contains = function (value, compareSelector) {
- /// <summary>Determines whether a sequence contains a specified element.</summary>
- /// <param name="value" type="T">The value to locate in the sequence.</param>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Boolean"></returns>
- compareSelector = Utils.createLambda(compareSelector);
- var enumerator = this.getEnumerator();
- try {
- while (enumerator.moveNext()) {
- if (compareSelector(enumerator.current()) === value) return true;
- }
- return false;
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- Enumerable.prototype.defaultIfEmpty = function (defaultValue) {
- /// <summary>Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.
- /// &#10;default of defautValue is null.</summary>
- /// <param name="defaultValue" type="T" optional="true">The value to return if the sequence is empty.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- if (defaultValue === undefined) defaultValue = null;
-
- return new Enumerable(function () {
- var enumerator;
- var isFirst = true;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (enumerator.moveNext()) {
- isFirst = false;
- return this.yieldReturn(enumerator.current());
- }
- else if (isFirst) {
- isFirst = false;
- return this.yieldReturn(defaultValue);
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function()
- // Overload:function(compareSelector)
- Enumerable.prototype.distinct = function (compareSelector) {
- /// <summary>Returns distinct elements from a sequence.</summary>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- return this.except(Enumerable.empty(), compareSelector);
- };
-
- Enumerable.prototype.distinctUntilChanged = function (compareSelector) {
- /// <summary>Returns distinct continuous elements from a sequence.</summary>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var compareKey;
- var initial;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- },
- function () {
- while (enumerator.moveNext()) {
- var key = compareSelector(enumerator.current());
-
- if (initial) {
- initial = false;
- compareKey = key;
- return this.yieldReturn(enumerator.current());
- }
-
- if (compareKey === key) {
- continue;
- }
-
- compareKey = key;
- return this.yieldReturn(enumerator.current());
- }
- return this.yieldBreak();
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.except = function (second, compareSelector) {
- /// <summary>Produces the set difference of two sequences.</summary>
- /// <param name="second" type="Enumerable&lt;T>">An Enumerable&lt;T> whose Elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.</param>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var keys;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- keys = new Dictionary(compareSelector);
- Enumerable.from(second).forEach(function (key) { keys.add(key); });
- },
- function () {
- while (enumerator.moveNext()) {
- var current = enumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.intersect = function (second, compareSelector) {
- /// <summary>Produces the set difference of two sequences.</summary>
- /// <param name="second" type="Enumerable&lt;T>">An Enumerable&lt;T> whose distinct elements that also appear in the first sequence will be returned.</param>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var keys;
- var outs;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
-
- keys = new Dictionary(compareSelector);
- Enumerable.from(second).forEach(function (key) { keys.add(key); });
- outs = new Dictionary(compareSelector);
- },
- function () {
- while (enumerator.moveNext()) {
- var current = enumerator.current();
- if (!outs.contains(current) && keys.contains(current)) {
- outs.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.sequenceEqual = function (second, compareSelector) {
- /// <summary>Determines whether two sequences are equal by comparing the elements.</summary>
- /// <param name="second" type="Enumerable&lt;T>">An Enumerable&lt;T> to compare to the first sequence.</param>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- compareSelector = Utils.createLambda(compareSelector);
-
- var firstEnumerator = this.getEnumerator();
- try {
- var secondEnumerator = Enumerable.from(second).getEnumerator();
- try {
- while (firstEnumerator.moveNext()) {
- if (!secondEnumerator.moveNext()
- || compareSelector(firstEnumerator.current()) !== compareSelector(secondEnumerator.current())) {
- return false;
- }
- }
-
- if (secondEnumerator.moveNext()) return false;
- return true;
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- }
- finally {
- Utils.dispose(firstEnumerator);
- }
- };
-
- Enumerable.prototype.union = function (second, compareSelector) {
- /// <summary>Produces the union of two sequences.</summary>
- /// <param name="second" type="Enumerable&lt;T>">An Enumerable&lt;T> whose distinct elements form the second set for the union.</param>
- /// <param name="compareSelector" type="Func&lt;T,TKey>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var keys;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- keys = new Dictionary(compareSelector);
- },
- function () {
- var current;
- if (secondEnumerator === undefined) {
- while (firstEnumerator.moveNext()) {
- current = firstEnumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- secondEnumerator = Enumerable.from(second).getEnumerator();
- }
- while (secondEnumerator.moveNext()) {
- current = secondEnumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- };
-
- /* Ordering Methods */
-
- Enumerable.prototype.orderBy = function (keySelector) {
- /// <signature>
- /// <summary>Sorts the elements of a sequence in ascending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from an element.</param>
- /// <returns type="OrderedEnumerable"></returns>
- /// </signature>
- /// <summary>Sorts the elements of a sequence in ascending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from an element.</param>
- return new OrderedEnumerable(this, keySelector, false);
- };
-
- Enumerable.prototype.orderByDescending = function (keySelector) {
- /// <signature>
- /// <summary>Sorts the elements of a sequence in descending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from an element.</param>
- /// <returns type="OrderedEnumerable"></returns>
- /// </signature>
- /// <summary>Sorts the elements of a sequence in descending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from an element.</param>
- return new OrderedEnumerable(this, keySelector, true);
- };
-
- Enumerable.prototype.reverse = function () {
- /// <summary>Inverts the order of the elements in a sequence.</summary>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
- var index;
-
- return new IEnumerator(
- function () {
- buffer = source.toArray();
- index = buffer.length;
- },
- function () {
- return (index > 0)
- ? this.yieldReturn(buffer[--index])
- : false;
- },
- Functions.Blank);
- });
- };
-
- Enumerable.prototype.shuffle = function () {
- /// <summary>Shuffle sequence.</summary>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
-
- return new IEnumerator(
- function () { buffer = source.toArray(); },
- function () {
- if (buffer.length > 0) {
- var i = Math.floor(Math.random() * buffer.length);
- return this.yieldReturn(buffer.splice(i, 1)[0]);
- }
- return false;
- },
- Functions.Blank);
- });
- };
-
- Enumerable.prototype.weightedSample = function (weightSelector) {
- /// <summary>Weighted sampling sequence by weightSelector. The result is infinite sequence.</summary>
- /// <param name="weightSelector" type="Func&lt;T,TKey>" optional="true">A function to select a weight from an element.</param>
- /// <returns type="Enumerable"></returns>
- weightSelector = Utils.createLambda(weightSelector);
- var source = this;
-
- return new Enumerable(function () {
- var sortedByBound;
- var totalWeight = 0;
-
- return new IEnumerator(
- function () {
- sortedByBound = source
- .choose(function (x) {
- var weight = weightSelector(x);
- if (weight <= 0) return null; // ignore 0
-
- totalWeight += weight;
- return { value: x, bound: totalWeight };
- })
- .toArray();
- },
- function () {
- if (sortedByBound.length > 0) {
- var draw = Math.floor(Math.random() * totalWeight) + 1;
-
- var lower = -1;
- var upper = sortedByBound.length;
- while (upper - lower > 1) {
- var index = Math.floor((lower + upper) / 2);
- if (sortedByBound[index].bound >= draw) {
- upper = index;
- }
- else {
- lower = index;
- }
- }
-
- return this.yieldReturn(sortedByBound[upper].value);
- }
-
- return this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- /* Grouping Methods */
-
- // Overload:function(keySelector)
- // Overload:function(keySelector,elementSelector)
- // Overload:function(keySelector,elementSelector,resultSelector)
- // Overload:function(keySelector,elementSelector,resultSelector,compareSelector)
- Enumerable.prototype.groupBy = function (keySelector, elementSelector, resultSelector, compareSelector) {
- /// <summary>Groups the elements of a sequence according to a specified key selector function.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract the key for each element.</param>
- /// <param name="elementSelector" type="Func&lt;T,TElement>" optional="true">A function to map each source element to an element in an Grouping&lt;TKey, TElement>.</param>
- /// <param name="resultSelector" type="Func&lt;TKey,Enumerable&lt;TElement>,TResult>" optional="true">A function to create a result value from each group.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- if (resultSelector != null) resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = source.toLookup(keySelector, elementSelector, compareSelector)
- .toEnumerable()
- .getEnumerator();
- },
- function () {
- while (enumerator.moveNext()) {
- return (resultSelector == null)
- ? this.yieldReturn(enumerator.current())
- : this.yieldReturn(resultSelector(enumerator.current().key(), enumerator.current()));
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(keySelector)
- // Overload:function(keySelector,elementSelector)
- // Overload:function(keySelector,elementSelector,resultSelector)
- // Overload:function(keySelector,elementSelector,resultSelector,compareSelector)
- Enumerable.prototype.partitionBy = function (keySelector, elementSelector, resultSelector, compareSelector) {
- /// <summary>Create Group by continuation key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract the key for each element.</param>
- /// <param name="elementSelector" type="Func&lt;T,TElement>" optional="true">A function to map each source element to an element in an Grouping&lt;TKey, TElement>.</param>
- /// <param name="resultSelector" type="Func&lt;TKey,Enumerable&lt;TElement>,TResult>" optional="true">A function to create a result value from each group.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var hasResultSelector;
- if (resultSelector == null) {
- hasResultSelector = false;
- resultSelector = function (key, group) { return new Grouping(key, group); };
- }
- else {
- hasResultSelector = true;
- resultSelector = Utils.createLambda(resultSelector);
- }
-
- return new Enumerable(function () {
- var enumerator;
- var key;
- var compareKey;
- var group = [];
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- if (enumerator.moveNext()) {
- key = keySelector(enumerator.current());
- compareKey = compareSelector(key);
- group.push(elementSelector(enumerator.current()));
- }
- },
- function () {
- var hasNext;
- while ((hasNext = enumerator.moveNext()) == true) {
- if (compareKey === compareSelector(keySelector(enumerator.current()))) {
- group.push(elementSelector(enumerator.current()));
- }
- else break;
- }
-
- if (group.length > 0) {
- var result = (hasResultSelector)
- ? resultSelector(key, Enumerable.from(group))
- : resultSelector(key, group);
- if (hasNext) {
- key = keySelector(enumerator.current());
- compareKey = compareSelector(key);
- group = [elementSelector(enumerator.current())];
- }
- else group = [];
-
- return this.yieldReturn(result);
- }
-
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.buffer = function (count) {
- /// <summary>Divide by count</summary>
- /// <param name="count" type="Number" integer="true">integer</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- var array = [];
- var index = 0;
- while (enumerator.moveNext()) {
- array.push(enumerator.current());
- if (++index >= count) return this.yieldReturn(array);
- }
- if (array.length > 0) return this.yieldReturn(array);
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- /* Aggregate Methods */
-
- // Overload:function(func)
- // Overload:function(seed,func)
- // Overload:function(seed,func,resultSelector)
- Enumerable.prototype.aggregate = function (seed, func, resultSelector) {
- /// <signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="func" type="Func&lt;TSource,TSource,TSource>">An accumulator function to be invoked on each element.</param>
- /// <returns type="TAccumulate"></returns>
- /// </signature>
- /// <signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="seed" type="TAccumulate">the initial accumulator value.</param>
- /// <param name="func" type="Func&lt;TAccumulate,TSource,TAccumulate>">An accumulator function to be invoked on each element.</param>
- /// <param name="resultSelector" type="Func&lt;TAccumulate,TResult>" optional="true">A function to transform the final accumulator value into the result value.</param>
- /// <returns type="TResult"></returns>
- /// </signature>
- /// <summary>Applies an accumulator function over a sequence.</summary>
- /// <param name="seed" type="Func&lt;T,T,T>_or_TAccumulate">Func is an accumulator function to be invoked on each element. Seed is the initial accumulator value.</param>
- /// <param name="func" type="Optional:Func&lt;TAccumulate,T,TAccumulate>" optional="true">An accumulator function to be invoked on each element.</param>
- /// <param name="resultSelector" type="Optional:Func&lt;TAccumulate,TResult>" optional="true">A function to transform the final accumulator value into the result value.</param>
- resultSelector = Utils.createLambda(resultSelector);
- return resultSelector(this.scan(seed, func, resultSelector).last());
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.average = function (selector) {
- /// <summary>Computes the average of a sequence.</summary>
- /// <param name="selector" type="Func&lt;T,Number>" optional="true">A transform function to apply to each element.</param>
- /// <returns type="Number"></returns>
- selector = Utils.createLambda(selector);
-
- var sum = 0;
- var count = 0;
- this.forEach(function (x) {
- sum += selector(x);
- ++count;
- });
-
- return sum / count;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.count = function (predicate) {
- /// <summary>Returns the number of elements in a sequence.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition.</param>
- /// <returns type="Number"></returns>
- predicate = (predicate == null) ? Functions.True : Utils.createLambda(predicate);
-
- var count = 0;
- this.forEach(function (x, i) {
- if (predicate(x, i))++count;
- });
- return count;
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.max = function (selector) {
- /// <summary>Returns the maximum value in a sequence</summary>
- /// <param name="selector" type="Func&lt;T,TKey>" optional="true">A transform function to apply to each element.</param>
- /// <returns type="Number"></returns>
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(function (a, b) { return (a > b) ? a : b; });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.min = function (selector) {
- /// <summary>Returns the minimum value in a sequence</summary>
- /// <param name="selector" type="Func&lt;T,TKey>" optional="true">A transform function to apply to each element.</param>
- /// <returns type="Number"></returns>
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(function (a, b) { return (a < b) ? a : b; });
- };
-
- Enumerable.prototype.maxBy = function (keySelector) {
- /// <summary>Returns the maximum value in a sequence by keySelector</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A compare selector of element.</param>
- /// <returns type="T"></returns>
- keySelector = Utils.createLambda(keySelector);
- return this.aggregate(function (a, b) { return (keySelector(a) > keySelector(b)) ? a : b; });
- };
-
- Enumerable.prototype.minBy = function (keySelector) {
- /// <summary>Returns the minimum value in a sequence by keySelector</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A compare selector of element.</param>
- /// <returns type="T"></returns>
- keySelector = Utils.createLambda(keySelector);
- return this.aggregate(function (a, b) { return (keySelector(a) < keySelector(b)) ? a : b; });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.sum = function (selector) {
- /// <summary>Computes the sum of a sequence of values.</summary>
- /// <param name="selector" type="Func&lt;T,TKey>" optional="true">A transform function to apply to each element.</param>
- /// <returns type="Number"></returns>
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(0, function (a, b) { return a + b; });
- };
-
- /* Paging Methods */
-
- Enumerable.prototype.elementAt = function (index) {
- /// <summary>Returns the element at a specified index in a sequence.</summary>
- /// <param name="index" type="Number" integer="true">The zero-based index of the element to retrieve.</param>
- /// <returns type="T"></returns>
- var value;
- var found = false;
- this.forEach(function (x, i) {
- if (i == index) {
- value = x;
- found = true;
- return false;
- }
- });
-
- if (!found) throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");
- return value;
- };
-
- Enumerable.prototype.elementAtOrDefault = function (index, defaultValue) {
- /// <summary>Returns the element at a specified index in a sequence or a default value if the index is out of range.
- /// &#10;default of defautValue is null.</summary>
- /// <param name="index" type="Number" integer="true">The zero-based index of the element to retrieve.</param>
- /// <param name="defaultValue" type="T" optional="true">The value if the index is outside the bounds then send.</param>
- /// <returns type="T"></returns>
- if (defaultValue === undefined) defaultValue = null;
- var value;
- var found = false;
- this.forEach(function (x, i) {
- if (i == index) {
- value = x;
- found = true;
- return false;
- }
- });
-
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.first = function (predicate) {
- /// <summary>Returns the first element of a sequence.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition.</param>
- /// <returns type="T"></returns>
- if (predicate != null) return this.where(predicate).first();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- value = x;
- found = true;
- return false;
- });
-
- if (!found) throw new Error("first:No element satisfies the condition.");
- return value;
- };
-
- Enumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
- /// <summary>Returns the first element of a sequence, or a default value.
- /// &#10;default of defautValue is null.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition. If null then no use predicate.</param>
- /// <param name="defaultValue" type="T" optional="true">The value if not found then send.</param>
- /// <returns type="T"></returns>
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).firstOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- value = x;
- found = true;
- return false;
- });
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.last = function (predicate) {
- /// <summary>Returns the last element of a sequence.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition.</param>
- /// <returns type="T"></returns>
- if (predicate != null) return this.where(predicate).last();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- found = true;
- value = x;
- });
-
- if (!found) throw new Error("last:No element satisfies the condition.");
- return value;
- };
-
- Enumerable.prototype.lastOrDefault = function (predicate, defaultValue) {
- /// <summary>Returns the last element of a sequence, or a default value.
- /// &#10;default of defautValue is null.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition. If null then no use predicate.</param>
- /// <param name="defaultValue" type="T" optional="true">The value if not found then send.</param>
- /// <returns type="T"></returns>
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).lastOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- found = true;
- value = x;
- });
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.single = function (predicate) {
- /// <summary>Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition.</param>
- /// <returns type="T"></returns>
- if (predicate != null) return this.where(predicate).single();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- if (!found) {
- found = true;
- value = x;
- } else throw new Error("single:sequence contains more than one element.");
- });
-
- if (!found) throw new Error("single:No element satisfies the condition.");
- return value;
- };
-
- // Overload:function(defaultValue)
- // Overload:function(defaultValue,predicate)
- Enumerable.prototype.singleOrDefault = function (predicate, defaultValue) {
- /// <summary>Returns a single, specific element of a sequence of values, or a default value if no such element is found.
- /// &#10;default of defautValue is null.</summary>
- /// <param name="predicate" type="Func&lt;T,Boolean>" optional="true">A function to test each element for a condition. If null then no use predicate.</param>
- /// <param name="defaultValue" type="T" optional="true">The value if not found then send.</param>
- /// <returns type="T"></returns>
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).singleOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- if (!found) {
- found = true;
- value = x;
- } else throw new Error("single:sequence contains more than one element.");
- });
-
- return (!found) ? defaultValue : value;
- };
-
- Enumerable.prototype.skip = function (count) {
- /// <summary>Bypasses a specified number of elements in a sequence and then returns the remaining elements.</summary>
- /// <param name="count" type="Number" integer="true">The number of elements to skip before returning the remaining elements.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- while (index++ < count && enumerator.moveNext()) {
- }
- ;
- },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.skipWhile = function (predicate) {
- /// <summary>Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.</summary>
- /// <param name="predicate" type="Func&lt;T,int,Boolean>">A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- predicate = Utils.createLambda(predicate);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
- var isSkipEnd = false;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (!isSkipEnd) {
- if (enumerator.moveNext()) {
- if (!predicate(enumerator.current(), index++)) {
- isSkipEnd = true;
- return this.yieldReturn(enumerator.current());
- }
- continue;
- } else return false;
- }
-
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
-
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.take = function (count) {
- /// <summary>Returns a specified number of contiguous elements from the start of a sequence.</summary>
- /// <param name="count" type="Number" integer="true">The number of elements to return.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (index++ < count && enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); }
- );
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.takeWhile = function (predicate) {
- /// <summary>Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.</summary>
- /// <param name="predicate" type="Func&lt;T,int,Boolean>">A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- predicate = Utils.createLambda(predicate);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext() && predicate(enumerator.current(), index++))
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function()
- // Overload:function(count)
- Enumerable.prototype.takeExceptLast = function (count) {
- /// <summary>Take a sequence except last count. The default count is 1.</summary>
- /// <param name="count" type="Number" integer="true" optional="true">The number of skip count.</param>
- /// <returns type="Enumerable"></returns>
- if (count == null) count = 1;
- var source = this;
-
- return new Enumerable(function () {
- if (count <= 0) return source.getEnumerator(); // do nothing
-
- var enumerator;
- var q = [];
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (q.length == count) {
- q.push(enumerator.current());
- return this.yieldReturn(q.shift());
- }
- q.push(enumerator.current());
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.takeFromLast = function (count) {
- /// <summary>Take a sequence from last count.</summary>
- /// <param name="count" type="Number" integer="true">The number of take count.</param>
- /// <returns type="Enumerable"></returns>
- if (count <= 0 || count == null) return Enumerable.empty();
- var source = this;
-
- return new Enumerable(function () {
- var sourceEnumerator;
- var enumerator;
- var q = [];
-
- return new IEnumerator(
- function () { sourceEnumerator = source.getEnumerator(); },
- function () {
- while (sourceEnumerator.moveNext()) {
- if (q.length == count) q.shift();
- q.push(sourceEnumerator.current());
- }
- if (enumerator == null) {
- enumerator = Enumerable.from(q).getEnumerator();
- }
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.indexOf = function (item) {
- /// <summary>Returns the zero-based index of the flrst occurrence of a value.</summary>
- /// <param name="item" type="T">The zero-based starting index of the search.</param>
- /// <returns type="Number" integer="true"></returns>
- var found = null;
-
- // item as predicate
- if (typeof (item) === Types.Function) {
- this.forEach(function (x, i) {
- if (item(x, i)) {
- found = i;
- return false;
- }
- });
- }
- else {
- this.forEach(function (x, i) {
- if (x === item) {
- found = i;
- return false;
- }
- });
- }
-
- return (found !== null) ? found : -1;
- };
-
- Enumerable.prototype.lastIndexOf = function (item) {
- /// <summary>Returns the zero-based index of the last occurrence of a value.</summary>
- /// <param name="item" type="T">The zero-based starting index of the search.</param>
- /// <returns type="Number" integer="true"></returns>
- var result = -1;
-
- // item as predicate
- if (typeof (item) === Types.Function) {
- this.forEach(function (x, i) {
- if (item(x, i)) result = i;
- });
- }
- else {
- this.forEach(function (x, i) {
- if (x === item) result = i;
- });
- }
-
- return result;
- };
-
- /* Convert Methods */
-
- Enumerable.prototype.cast = function () {
- return this;
- };
-
- Enumerable.prototype.asEnumerable = function () {
- /// <summary>Convert sequence as enumerable. This same as Enumerable.from(seq).</summary>
- /// <returns type="Enumerable"></returns>
- return Enumerable.from(this);
- };
-
- Enumerable.prototype.toArray = function () {
- /// <summary>Creates an array from this sequence.</summary>
- /// <returns type="Array"></returns>
- var array = [];
- this.forEach(function (x) { array.push(x); });
- return array;
- };
-
- // Overload:function(keySelector)
- // Overload:function(keySelector, elementSelector)
- // Overload:function(keySelector, elementSelector, compareSelector)
- Enumerable.prototype.toLookup = function (keySelector, elementSelector, compareSelector) {
- /// <summary>Creates a Lookup from this sequence.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from each element.</param>
- /// <param name="elementSelector" type="Func&lt;T,TElement>" optional="true">A transform function to produce a result element value from each element.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- var dict = new Dictionary(compareSelector);
- this.forEach(function (x) {
- var key = keySelector(x);
- var element = elementSelector(x);
-
- var array = dict.get(key);
- if (array !== undefined) array.push(element);
- else dict.add(key, [element]);
- });
- return new Lookup(dict);
- };
-
- Enumerable.prototype.toObject = function (keySelector, elementSelector) {
- /// <summary>Creates a Object from this sequence.</summary>
- /// <param name="keySelector" type="Func&lt;T,String>" optional="true">A function to extract a key from each element.</param>
- /// <param name="elementSelector" type="Func&lt;T,TElement>" optional="true">A transform function to produce a result element value from each element.</param>
- /// <returns type="Object"></returns>
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
-
- var obj = {};
- this.forEach(function (x) {
- obj[keySelector(x)] = elementSelector(x);
- });
- return obj;
- };
-
- // Overload:function(keySelector, elementSelector)
- // Overload:function(keySelector, elementSelector, compareSelector)
- Enumerable.prototype.toDictionary = function (keySelector, elementSelector, compareSelector) {
- /// <summary>Creates a Dictionary from this sequence.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>" optional="true">A function to extract a key from each element.</param>
- /// <param name="elementSelector" type="Func&lt;T,TElement>" optional="true">A transform function to produce a result element value from each element.</param>
- /// <param name="compareSelector" type="Func&lt;TKey,TCompare>" optional="true">An equality comparer to compare values.</param>
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- var dict = new Dictionary(compareSelector);
- this.forEach(function (x) {
- dict.add(keySelector(x), elementSelector(x));
- });
- return dict;
- };
-
- // Overload:function()
- // Overload:function(replacer)
- // Overload:function(replacer, space)
- Enumerable.prototype.toJSONString = function (replacer, space) {
- /// <summary>Creates a JSON String from sequence, performed only native JSON support browser or included json2.js.</summary>
- /// <param name="replacer" type="Function" optional="true">a replacer.</param>
- /// <param name="space" type="Number" optional="true">indent spaces.</param>
- /// <returns type="String"></returns>
- if (typeof JSON === Types.Undefined || JSON.stringify == null) {
- throw new Error("toJSONString can't find JSON.stringify. This works native JSON support Browser or include json2.js");
- }
- return JSON.stringify(this.toArray(), replacer, space);
- };
-
- // Overload:function()
- // Overload:function(separator)
- // Overload:function(separator,selector)
- Enumerable.prototype.toJoinedString = function (separator, selector) {
- /// <summary>Creates Joined string from this sequence. The default separator is "".</summary>
- /// <param name="separator" type="String" optional="true">A String.</param>
- /// <param name="selector" type="Func&lt;T,String>" optional="true">A transform function to apply to each source element.</param>
- /// <returns type="String"></returns>
- if (separator == null) separator = "";
- if (selector == null) selector = Functions.Identity;
-
- return this.select(selector).toArray().join(separator);
- };
-
-
- /* Action Methods */
-
- // Overload:function(action<element>)
- // Overload:function(action<element,index>)
- Enumerable.prototype.doAction = function (action) {
- /// <summary>Performs the specified action on each element of the sequence.</summary>
- /// <param name="action" type="Action&lt;T,int>">action on each element. Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="Enumerable"></returns>
- var source = this;
- action = Utils.createLambda(action);
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (enumerator.moveNext()) {
- action(enumerator.current(), index++);
- return this.yieldReturn(enumerator.current());
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(action<element>)
- // Overload:function(action<element,index>)
- // Overload:function(func<element,bool>)
- // Overload:function(func<element,index,bool>)
- Enumerable.prototype.forEach = function (action) {
- /// <summary>Performs the specified action on each element of the sequence.</summary>
- /// <param name="action" type="Action&lt;T,int>">[return true;]continue iteration.[return false;]break iteration. Optional:the second parameter of the function represents the index of the source element.</param>
- /// <returns type="void"></returns>
- action = Utils.createLambda(action);
-
- var index = 0;
- var enumerator = this.getEnumerator();
- try {
- while (enumerator.moveNext()) {
- if (action(enumerator.current(), index++) === false) break;
- }
- } finally {
- Utils.dispose(enumerator);
- }
- };
-
- // Overload:function()
- // Overload:function(separator)
- // Overload:function(separator,selector)
- Enumerable.prototype.write = function (separator, selector) {
- /// <summary>Do document.write.</summary>
- /// <param name="separator" type="String" optional="true">A String.</param>
- /// <param name="selector" type="Func&lt;T,String>" optional="true">A transform function to apply to each source element.</param>
- /// <returns type="void"></returns>
- if (separator == null) separator = "";
- selector = Utils.createLambda(selector);
-
- var isFirst = true;
- this.forEach(function (item) {
- if (isFirst) isFirst = false;
- else document.write(separator);
- document.write(selector(item));
- });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.writeLine = function (selector) {
- /// <summary>Do document.writeln + br.</summary>
- /// <param name="selector" type="Func&lt;T,String>" optional="true">A transform function to apply to each source element.</param>
- /// <returns type="void"></returns>
- selector = Utils.createLambda(selector);
-
- this.forEach(function (item) {
- document.writeln(selector(item) + "<br />");
- });
- };
-
- Enumerable.prototype.force = function () {
- /// <summary>Execute enumerate.</summary>
- /// <returns type="void"></returns>
- var enumerator = this.getEnumerator();
-
- try {
- while (enumerator.moveNext()) {
- }
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- /* Functional Methods */
-
- Enumerable.prototype.letBind = function (func) {
- /// <summary>Bind the source to the parameter so that it can be used multiple times.</summary>
- /// <param name="func" type="Func&lt;Enumerable&lt;T>,Enumerable&lt;TR>>">apply function.</param>
- /// <returns type="Enumerable"></returns>
- func = Utils.createLambda(func);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = Enumerable.from(func(source)).getEnumerator();
- },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.share = function () {
- /// <signature>
- /// <summary>Shares cursor of all enumerators to the sequence.</summary>
- /// <returns type="DisposableEnumerable"></returns>
- /// </signature>
- /// <summary>Shares cursor of all enumerators to the sequence.</summary>
- /// <returns type="Enumerable"></returns>
- var source = this;
- var sharedEnumerator;
- var disposed = false;
-
- return new DisposableEnumerable(function () {
- return new IEnumerator(
- function () {
- if (sharedEnumerator == null) {
- sharedEnumerator = source.getEnumerator();
- }
- },
- function () {
- if (disposed) throw new Error("enumerator is disposed");
-
- return (sharedEnumerator.moveNext())
- ? this.yieldReturn(sharedEnumerator.current())
- : false;
- },
- Functions.Blank
- );
- }, function () {
- disposed = true;
- Utils.dispose(sharedEnumerator);
- });
- };
-
- Enumerable.prototype.memoize = function () {
- /// <signature>
- /// <summary>Creates an enumerable that enumerates the original enumerable only once and caches its results.</summary>
- /// <returns type="DisposableEnumerable"></returns>
- /// </signature>
- /// <summary>Creates an enumerable that enumerates the original enumerable only once and caches its results.</summary>
- /// <returns type="Enumerable"></returns>
- var source = this;
- var cache;
- var enumerator;
- var disposed = false;
-
- return new DisposableEnumerable(function () {
- var index = -1;
-
- return new IEnumerator(
- function () {
- if (enumerator == null) {
- enumerator = source.getEnumerator();
- cache = [];
- }
- },
- function () {
- if (disposed) throw new Error("enumerator is disposed");
-
- index++;
- if (cache.length <= index) {
- return (enumerator.moveNext())
- ? this.yieldReturn(cache[index] = enumerator.current())
- : false;
- }
-
- return this.yieldReturn(cache[index]);
- },
- Functions.Blank
- );
- }, function () {
- disposed = true;
- Utils.dispose(enumerator);
- cache = null;
- });
- };
-
- /* Error Handling Methods */
-
- Enumerable.prototype.catchError = function (handler) {
- /// <summary>catch error and do handler.</summary>
- /// <param name="handler" type="Action&lt;Error>">execute if error occured.</param>
- /// <returns type="Enumerable"></returns>
- handler = Utils.createLambda(handler);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- try {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- } catch (e) {
- handler(e);
- return false;
- }
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.finallyAction = function (finallyAction) {
- /// <summary>do action if enumerate end or disposed or error occured.</summary>
- /// <param name="finallyAction" type="Action">finally execute.</param>
- /// <returns type="Enumerable"></returns>
- finallyAction = Utils.createLambda(finallyAction);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () {
- try {
- Utils.dispose(enumerator);
- } finally {
- finallyAction();
- }
- });
- });
- };
-
- /* For Debug Methods */
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.log = function (selector) {
- /// <summary>log object use console.log.</summary>
- /// <param name="selector" type="Func&lt;T,String>" optional="true">A transform function to apply to each source element.</param>
- /// <returns type="Enumerable"></returns>
- selector = Utils.createLambda(selector);
-
- return this.doAction(function (item) {
- if (typeof console !== Types.Undefined) {
- console.log(selector(item));
- }
- });
- };
-
- // Overload:function()
- // Overload:function(message)
- // Overload:function(message,selector)
- Enumerable.prototype.trace = function (message, selector) {
- /// <summary>Trace object use console.log.</summary>
- /// <param name="message" type="String" optional="true">Default is 'Trace'.</param>
- /// <param name="selector" type="Func&lt;T,String>" optional="true">A transform function to apply to each source element.</param>
- /// <returns type="Enumerable"></returns>
- if (message == null) message = "Trace";
- selector = Utils.createLambda(selector);
-
- return this.doAction(function (item) {
- if (typeof console !== Types.Undefined) {
- console.log(message, selector(item));
- }
- });
- };
-
- // private
-
- var OrderedEnumerable = function (source, keySelector, descending, parent) {
- this.source = source;
- this.keySelector = Utils.createLambda(keySelector);
- this.descending = descending;
- this.parent = parent;
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
- OrderedEnumerable.prototype = new Enumerable();
-
- OrderedEnumerable.prototype.createOrderedEnumerable = function (keySelector, descending) {
- return new OrderedEnumerable(this.source, keySelector, descending, this);
- };
- OrderedEnumerable.prototype.thenBy = function (keySelector) {
- /// <signature>
- /// <summary>Performs a subsequent ordering of the elements in a sequence in ascending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A function to extract a key from each element.</param>
- /// <returns type="OrderedEnumerable"></returns>
- /// </signature>
- /// <summary>Performs a subsequent ordering of the elements in a sequence in ascending order according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A function to extract a key from each element.</param>
- return this.createOrderedEnumerable(keySelector, false);
- };
- OrderedEnumerable.prototype.thenByDescending = function (keySelector) {
- /// <signature>
- /// <summary>Performs a subsequent ordering of the elements in a sequence in descending order, according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A function to extract a key from each element.</param>
- /// <returns type="OrderedEnumerable"></returns>
- /// </signature>
- /// <summary>Performs a subsequent ordering of the elements in a sequence in descending order, according to a key.</summary>
- /// <param name="keySelector" type="Func&lt;T,TKey>">A function to extract a key from each element.</param>
- return this.createOrderedEnumerable(keySelector, true);
- };
- OrderedEnumerable.prototype.getEnumerator = function () {
- /// <summary>Returns an enumerator that iterates through the collection.</summary>
- /// <returns type="IEnumerator"></returns>
- var self = this;
- var buffer;
- var indexes;
- var index = 0;
-
- return new IEnumerator(
- function () {
- buffer = [];
- indexes = [];
- self.source.forEach(function (item, index) {
- buffer.push(item);
- indexes.push(index);
- });
- var sortContext = SortContext.create(self, null);
- sortContext.GenerateKeys(buffer);
-
- indexes.sort(function (a, b) { return sortContext.compare(a, b); });
- },
- function () {
- return (index < indexes.length)
- ? this.yieldReturn(buffer[indexes[index++]])
- : false;
- },
- Functions.Blank
- );
- };
-
- var SortContext = function (keySelector, descending, child) {
- this.keySelector = keySelector;
- this.descending = descending;
- this.child = child;
- this.keys = null;
- };
- SortContext.create = function (orderedEnumerable, currentContext) {
- var context = new SortContext(orderedEnumerable.keySelector, orderedEnumerable.descending, currentContext);
- if (orderedEnumerable.parent != null) return SortContext.create(orderedEnumerable.parent, context);
- return context;
- };
- SortContext.prototype.GenerateKeys = function (source) {
- var len = source.length;
- var keySelector = this.keySelector;
- var keys = new Array(len);
- for (var i = 0; i < len; i++) keys[i] = keySelector(source[i]);
- this.keys = keys;
-
- if (this.child != null) this.child.GenerateKeys(source);
- };
- SortContext.prototype.compare = function (index1, index2) {
- var comparison = Utils.compare(this.keys[index1], this.keys[index2]);
-
- if (comparison == 0) {
- if (this.child != null) return this.child.compare(index1, index2);
- comparison = Utils.compare(index1, index2);
- }
-
- return (this.descending) ? -comparison : comparison;
- };
-
- var DisposableEnumerable = function (getEnumerator, dispose) {
- /// <field name="dispose" type="Function">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</field>
- this.dispose = dispose;
- Enumerable.call(this, getEnumerator);
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
- DisposableEnumerable.prototype = new Enumerable();
-
- // optimize array or arraylike object
-
- var ArrayEnumerable = function (source) {
- this.getSource = function () { return source; };
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
- ArrayEnumerable.prototype = new Enumerable();
-
- ArrayEnumerable.prototype.any = function (predicate) {
- return (predicate == null)
- ? (this.getSource().length > 0)
- : Enumerable.prototype.any.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.count = function (predicate) {
- return (predicate == null)
- ? this.getSource().length
- : Enumerable.prototype.count.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.elementAt = function (index) {
- var source = this.getSource();
- return (0 <= index && index < source.length)
- ? source[index]
- : Enumerable.prototype.elementAt.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.elementAtOrDefault = function (index, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- var source = this.getSource();
- return (0 <= index && index < source.length)
- ? source[index]
- : defaultValue;
- };
-
- ArrayEnumerable.prototype.first = function (predicate) {
- var source = this.getSource();
- return (predicate == null && source.length > 0)
- ? source[0]
- : Enumerable.prototype.first.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) {
- return Enumerable.prototype.firstOrDefault.apply(this, arguments);
- }
-
- var source = this.getSource();
- return source.length > 0 ? source[0] : defaultValue;
- };
-
- ArrayEnumerable.prototype.last = function (predicate) {
- var source = this.getSource();
- return (predicate == null && source.length > 0)
- ? source[source.length - 1]
- : Enumerable.prototype.last.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.lastOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) {
- return Enumerable.prototype.lastOrDefault.apply(this, arguments);
- }
-
- var source = this.getSource();
- return source.length > 0 ? source[source.length - 1] : defaultValue;
- };
-
- ArrayEnumerable.prototype.skip = function (count) {
- var source = this.getSource();
-
- return new Enumerable(function () {
- var index;
-
- return new IEnumerator(
- function () { index = (count < 0) ? 0 : count; },
- function () {
- return (index < source.length)
- ? this.yieldReturn(source[index++])
- : false;
- },
- Functions.Blank);
- });
- };
-
- ArrayEnumerable.prototype.takeExceptLast = function (count) {
- if (count == null) count = 1;
- return this.take(this.getSource().length - count);
- };
-
- ArrayEnumerable.prototype.takeFromLast = function (count) {
- return this.skip(this.getSource().length - count);
- };
-
- ArrayEnumerable.prototype.reverse = function () {
- var source = this.getSource();
-
- return new Enumerable(function () {
- var index;
-
- return new IEnumerator(
- function () {
- index = source.length;
- },
- function () {
- return (index > 0)
- ? this.yieldReturn(source[--index])
- : false;
- },
- Functions.Blank);
- });
- };
-
- ArrayEnumerable.prototype.sequenceEqual = function (second, compareSelector) {
- if ((second instanceof ArrayEnumerable || second instanceof Array)
- && compareSelector == null
- && Enumerable.from(second).count() != this.count()) {
- return false;
- }
-
- return Enumerable.prototype.sequenceEqual.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.toJoinedString = function (separator, selector) {
- var source = this.getSource();
- if (selector != null || !(source instanceof Array)) {
- return Enumerable.prototype.toJoinedString.apply(this, arguments);
- }
-
- if (separator == null) separator = "";
- return source.join(separator);
- };
-
- ArrayEnumerable.prototype.getEnumerator = function () {
- var source = this.getSource();
- var index = -1;
-
- // fast and simple enumerator
- return {
- current: function () { return source[index]; },
- moveNext: function () {
- return ++index < source.length;
- },
- dispose: Functions.Blank
- };
- };
-
- // optimization for multiple where and multiple select and whereselect
-
- var WhereEnumerable = function (source, predicate) {
- this.prevSource = source;
- this.prevPredicate = predicate; // predicate.length always <= 1
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
- WhereEnumerable.prototype = new Enumerable();
-
- WhereEnumerable.prototype.where = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- if (predicate.length <= 1) {
- var prevPredicate = this.prevPredicate;
- var composedPredicate = function (x) { return prevPredicate(x) && predicate(x); };
- return new WhereEnumerable(this.prevSource, composedPredicate);
- }
- else {
- // if predicate use index, can't compose
- return Enumerable.prototype.where.call(this, predicate);
- }
- };
-
- WhereEnumerable.prototype.select = function (selector) {
- selector = Utils.createLambda(selector);
-
- return (selector.length <= 1)
- ? new WhereSelectEnumerable(this.prevSource, this.prevPredicate, selector)
- : Enumerable.prototype.select.call(this, selector);
- };
-
- WhereEnumerable.prototype.getEnumerator = function () {
- var predicate = this.prevPredicate;
- var source = this.prevSource;
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate(enumerator.current())) {
- return this.yieldReturn(enumerator.current());
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- };
-
- var WhereSelectEnumerable = function (source, predicate, selector) {
- this.prevSource = source;
- this.prevPredicate = predicate; // predicate.length always <= 1 or null
- this.prevSelector = selector; // selector.length always <= 1
-
- if (intellisense) this.firstOrDefault(); // for intellisense
- };
- WhereSelectEnumerable.prototype = new Enumerable();
-
- WhereSelectEnumerable.prototype.where = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- return (predicate.length <= 1)
- ? new WhereEnumerable(this, predicate)
- : Enumerable.prototype.where.call(this, predicate);
- };
-
- WhereSelectEnumerable.prototype.select = function (selector) {
- selector = Utils.createLambda(selector);
-
- if (selector.length <= 1) {
- var prevSelector = this.prevSelector;
- var composedSelector = function (x) { return selector(prevSelector(x)); };
- return new WhereSelectEnumerable(this.prevSource, this.prevPredicate, composedSelector);
- }
- else {
- // if selector use index, can't compose
- return Enumerable.prototype.select.call(this, selector);
- }
- };
-
- WhereSelectEnumerable.prototype.getEnumerator = function () {
- var predicate = this.prevPredicate;
- var selector = this.prevSelector;
- var source = this.prevSource;
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate == null || predicate(enumerator.current())) {
- return this.yieldReturn(selector(enumerator.current()));
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- };
-
- // Collections
-
- var Dictionary = (function () {
- // static utility methods
- var callHasOwnProperty = function (target, key) {
- return Object.prototype.hasOwnProperty.call(target, key);
- };
-
- var computeHashCode = function (obj) {
- if (obj === null) return "null";
- if (obj === undefined) return "undefined";
-
- return (typeof obj.toString === Types.Function)
- ? obj.toString()
- : Object.prototype.toString.call(obj);
- };
-
- // LinkedList for Dictionary
- var HashEntry = function (key, value) {
- this.key = key;
- this.value = value;
- this.prev = null;
- this.next = null;
- };
-
- var EntryList = function () {
- this.first = null;
- this.last = null;
- };
- EntryList.prototype =
- {
- addLast: function (entry) {
- if (this.last != null) {
- this.last.next = entry;
- entry.prev = this.last;
- this.last = entry;
- } else this.first = this.last = entry;
- },
-
- replace: function (entry, newEntry) {
- if (entry.prev != null) {
- entry.prev.next = newEntry;
- newEntry.prev = entry.prev;
- } else this.first = newEntry;
-
- if (entry.next != null) {
- entry.next.prev = newEntry;
- newEntry.next = entry.next;
- } else this.last = newEntry;
-
- },
-
- remove: function (entry) {
- if (entry.prev != null) entry.prev.next = entry.next;
- else this.first = entry.next;
-
- if (entry.next != null) entry.next.prev = entry.prev;
- else this.last = entry.prev;
- }
- };
-
- // Overload:function()
- // Overload:function(compareSelector)
- var Dictionary = function (compareSelector) {
- this.countField = 0;
- this.entryList = new EntryList();
- this.buckets = {}; // as Dictionary<string,List<object>>
- this.compareSelector = (compareSelector == null) ? Functions.Identity : compareSelector;
- };
- Dictionary.prototype =
- {
- add: function (key, value) {
- /// <summary>add new pair. if duplicate key then overwrite new value.</summary>
- /// <returns type="Void"></returns>
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- var entry = new HashEntry(key, value);
- if (callHasOwnProperty(this.buckets, hash)) {
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- this.entryList.replace(array[i], entry);
- array[i] = entry;
- return;
- }
- }
- array.push(entry);
- } else {
- this.buckets[hash] = [entry];
- }
- this.countField++;
- this.entryList.addLast(entry);
- },
-
- get: function (key) {
- /// <summary>get value. if not find key then return undefined.</summary>
- /// <returns type="T"></returns>
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return undefined;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- var entry = array[i];
- if (this.compareSelector(entry.key) === compareKey) return entry.value;
- }
- return undefined;
- },
-
- set: function (key, value) {
- /// <summary>set value. if complete set value then return true, not find key then return false.</summary>
- /// <returns type="Boolean"></returns>
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (callHasOwnProperty(this.buckets, hash)) {
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- var newEntry = new HashEntry(key, value);
- this.entryList.replace(array[i], newEntry);
- array[i] = newEntry;
- return true;
- }
- }
- }
- return false;
- },
-
- contains: function (key) {
- /// <summary>check contains key.</summary>
- /// <returns type="Boolean"></returns>
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return false;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) return true;
- }
- return false;
- },
-
- clear: function () {
- /// <summary>clear dictionary.</summary>
- /// <returns type="Void"></returns>
- this.countField = 0;
- this.buckets = {};
- this.entryList = new EntryList();
- },
-
- remove: function (key) {
- /// <summary>remove key and value.</summary>
- /// <returns type="Void"></returns>
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- this.entryList.remove(array[i]);
- array.splice(i, 1);
- if (array.length == 0) delete this.buckets[hash];
- this.countField--;
- return;
- }
- }
- },
-
- count: function () {
- /// <summary>contains value's count.</summary>
- /// <returns type="Number"></returns>
- return this.countField;
- },
-
- toEnumerable: function () {
- /// <summary>Convert to Enumerable&lt;{key:, value:}&gt;.</summary>
- /// <returns type="Enumerable"></returns>
- var self = this;
- return new Enumerable(function () {
- var currentEntry;
-
- return new IEnumerator(
- function () { currentEntry = self.entryList.first; },
- function () {
- if (currentEntry != null) {
- var result = { key: currentEntry.key, value: currentEntry.value };
- currentEntry = currentEntry.next;
- return this.yieldReturn(result);
- }
- return false;
- },
- Functions.Blank);
- });
- }
- };
-
- return Dictionary;
- })();
-
- // dictionary = Dictionary<TKey, TValue[]>
- var Lookup = function (dictionary) {
- this.count = function () {
- /// <summary>contains value's count.</summary>
- /// <returns type="Number"></returns>
- return dictionary.count();
- };
- this.get = function (key) {
- /// <summary>get grouped enumerable.</summary>
- /// <returns type="Enumerable"></returns>
- return Enumerable.from(dictionary.get(key));
- };
- this.contains = function (key) {
- /// <summary>check contains key.</summary>
- /// <returns type="Boolean"></returns>
- return dictionary.contains(key);
- };
- this.toEnumerable = function () {
- /// <summary>Convert to Enumerable&lt;Grouping&gt;.</summary>
- /// <returns type="Enumerable"></returns>
- return dictionary.toEnumerable().select(function (kvp) {
- return new Grouping(kvp.key, kvp.value);
- });
- };
- };
-
- var Grouping = function (groupKey, elements) {
- this.key = function () {
- /// <summary>get grouping key.</summary>
- /// <returns type="T"></returns>
- return groupKey;
- };
- ArrayEnumerable.call(this, elements);
- };
- Grouping.prototype = new ArrayEnumerable();
-
- // module export
- if (typeof define === Types.Function && define.amd) { // AMD
- define("linqjs", [], function () { return Enumerable; });
- }
- else if (typeof module !== Types.Undefined && module.exports) { // Node
- module.exports = Enumerable;
- }
- else {
- root.Enumerable = Enumerable;
- }
-
- // vsdoc helper for VS2012
- var redirectDefinition;
- if(intellisense){
- redirectDefinition = function (from, redirectTo) {
- for (var methodName in from) {
- if (redirectTo[methodName] !== undefined) {
- intellisense.redirectDefinition(from[methodName], redirectTo[methodName]);
- }
- }
- };
- }
- else{
- redirectDefinition = Functions.Identity;
- }
-
- redirectDefinition(ArrayEnumerable.prototype, Enumerable.prototype);
- redirectDefinition(WhereEnumerable.prototype, Enumerable.prototype);
- redirectDefinition(WhereSelectEnumerable.prototype, Enumerable.prototype);
-
-})(this);
\ No newline at end of file
diff --git a/data/libs/linqjs/linq.jquery.js b/data/libs/linqjs/linq.jquery.js
deleted file mode 100644
index e426a1bbd..000000000
--- a/data/libs/linqjs/linq.jquery.js
+++ /dev/null
@@ -1,28 +0,0 @@
-// extension for jQuery
-
-(function (root) {
- if (root.Enumerable == null) {
- throw new Error("can't find Enumerable. linq.jquery.js must load after linq.js");
- }
- if (root.jQuery == null) {
- throw new Error("can't find jQuery. linq.jquery.js must load after jQuery");
- }
-
- var Enumerable = root.Enumerable;
- var $ = root.jQuery;
-
- $.fn.toEnumerable = function () {
- /// <summary>each contains elements. to Enumerable&lt;jQuery&gt;.</summary>
- return Enumerable.from(this).select(function (e) { return $(e) });
- };
-
- Enumerable.prototype.tojQuery = function () {
- /// <summary>Enumerable to jQuery. All elements add to blank jQuery object.</summary>
- return this.aggregate($(), function (j, x) { return j.add(x); });
- };
-
- Enumerable.prototype.tojQueryAsArray = function () {
- /// <summary>Enumerable to jQuery. This behavior is $(this.toArray()).</summary>
- return $(this.toArray());
- };
-})(this);
\ No newline at end of file
diff --git a/data/libs/linqjs/linq.js b/data/libs/linqjs/linq.js
deleted file mode 100644
index ee2f7ddce..000000000
--- a/data/libs/linqjs/linq.js
+++ /dev/null
@@ -1,3017 +0,0 @@
-/*--------------------------------------------------------------------------
- * linq.js - LINQ for JavaScript
- * ver 3.0.4-Beta5 (Jun. 20th, 2013)
- *
- * created and maintained by neuecc <[email protected]>
- * licensed under MIT License
- * http://linqjs.codeplex.com/
- *------------------------------------------------------------------------*/
-
-(function (root, undefined) {
- // ReadOnly Function
- var Functions = {
- Identity: function (x) { return x; },
- True: function () { return true; },
- Blank: function () { }
- };
-
- // const Type
- var Types = {
- Boolean: typeof true,
- Number: typeof 0,
- String: typeof "",
- Object: typeof {},
- Undefined: typeof undefined,
- Function: typeof function () { }
- };
-
- // createLambda cache
- var funcCache = { "": Functions.Identity };
-
- // private utility methods
- var Utils = {
- // Create anonymous function from lambda expression string
- createLambda: function (expression) {
- if (expression == null) return Functions.Identity;
- if (typeof expression === Types.String) {
- // get from cache
- var f = funcCache[expression];
- if (f != null) {
- return f;
- }
-
- if (expression.indexOf("=>") === -1) {
- var regexp = new RegExp("[$]+", "g");
-
- var maxLength = 0;
- var match;
- while ((match = regexp.exec(expression)) != null) {
- var paramNumber = match[0].length;
- if (paramNumber > maxLength) {
- maxLength = paramNumber;
- }
- }
-
- var argArray = [];
- for (var i = 1; i <= maxLength; i++) {
- var dollar = "";
- for (var j = 0; j < i; j++) {
- dollar += "$";
- }
- argArray.push(dollar);
- }
-
- var args = Array.prototype.join.call(argArray, ",");
-
- f = new Function(args, "return " + expression);
- funcCache[expression] = f;
- return f;
- }
- else {
- var expr = expression.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);
- f = new Function(expr[1], "return " + expr[2]);
- funcCache[expression] = f;
- return f;
- }
- }
- return expression;
- },
-
- isIEnumerable: function (obj) {
- if (typeof Enumerator !== Types.Undefined) {
- try {
- new Enumerator(obj); // check JScript(IE)'s Enumerator
- return true;
- }
- catch (e) { }
- }
-
- return false;
- },
-
- // IE8's defineProperty is defined but cannot use, therefore check defineProperties
- defineProperty: (Object.defineProperties != null)
- ? function (target, methodName, value) {
- Object.defineProperty(target, methodName, {
- enumerable: false,
- configurable: true,
- writable: true,
- value: value
- })
- }
- : function (target, methodName, value) {
- target[methodName] = value;
- },
-
- compare: function (a, b) {
- return (a === b) ? 0
- : (a > b) ? 1
- : -1;
- },
-
- dispose: function (obj) {
- if (obj != null) obj.dispose();
- }
- };
-
- // IEnumerator State
- var State = { Before: 0, Running: 1, After: 2 };
-
- // "Enumerator" is conflict JScript's "Enumerator"
- var IEnumerator = function (initialize, tryGetNext, dispose) {
- var yielder = new Yielder();
- var state = State.Before;
-
- this.current = yielder.current;
-
- this.moveNext = function () {
- try {
- switch (state) {
- case State.Before:
- state = State.Running;
- initialize();
- // fall through
- case State.Running:
- if (tryGetNext.apply(yielder)) {
- return true;
- }
- else {
- this.dispose();
- return false;
- }
- case State.After:
- return false;
- }
- }
- catch (e) {
- this.dispose();
- throw e;
- }
- };
-
- this.dispose = function () {
- if (state != State.Running) return;
-
- try {
- dispose();
- }
- finally {
- state = State.After;
- }
- };
- };
-
- // for tryGetNext
- var Yielder = function () {
- var current = null;
- this.current = function () { return current; };
- this.yieldReturn = function (value) {
- current = value;
- return true;
- };
- this.yieldBreak = function () {
- return false;
- };
- };
-
- // Enumerable constuctor
- var Enumerable = function (getEnumerator) {
- this.getEnumerator = getEnumerator;
- };
-
- // Utility
-
- Enumerable.Utils = {}; // container
-
- Enumerable.Utils.createLambda = function (expression) {
- return Utils.createLambda(expression);
- };
-
- Enumerable.Utils.createEnumerable = function (getEnumerator) {
- return new Enumerable(getEnumerator);
- };
-
- Enumerable.Utils.createEnumerator = function (initialize, tryGetNext, dispose) {
- return new IEnumerator(initialize, tryGetNext, dispose);
- };
-
- Enumerable.Utils.extendTo = function (type) {
- var typeProto = type.prototype;
- var enumerableProto;
-
- if (type === Array) {
- enumerableProto = ArrayEnumerable.prototype;
- Utils.defineProperty(typeProto, "getSource", function () {
- return this;
- });
- }
- else {
- enumerableProto = Enumerable.prototype;
- Utils.defineProperty(typeProto, "getEnumerator", function () {
- return Enumerable.from(this).getEnumerator();
- });
- }
-
- for (var methodName in enumerableProto) {
- var func = enumerableProto[methodName];
-
- // already extended
- if (typeProto[methodName] == func) continue;
-
- // already defined(example Array#reverse/join/forEach...)
- if (typeProto[methodName] != null) {
- methodName = methodName + "ByLinq";
- if (typeProto[methodName] == func) continue; // recheck
- }
-
- if (func instanceof Function) {
- Utils.defineProperty(typeProto, methodName, func);
- }
- }
- };
-
- // Generator
-
- Enumerable.choice = function () // variable argument
- {
- var args = arguments;
-
- return new Enumerable(function () {
- return new IEnumerator(
- function () {
- args = (args[0] instanceof Array) ? args[0]
- : (args[0].getEnumerator != null) ? args[0].toArray()
- : args;
- },
- function () {
- return this.yieldReturn(args[Math.floor(Math.random() * args.length)]);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.cycle = function () // variable argument
- {
- var args = arguments;
-
- return new Enumerable(function () {
- var index = 0;
- return new IEnumerator(
- function () {
- args = (args[0] instanceof Array) ? args[0]
- : (args[0].getEnumerator != null) ? args[0].toArray()
- : args;
- },
- function () {
- if (index >= args.length) index = 0;
- return this.yieldReturn(args[index++]);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.empty = function () {
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return false; },
- Functions.Blank);
- });
- };
-
- Enumerable.from = function (obj) {
- if (obj == null) {
- return Enumerable.empty();
- }
- if (obj instanceof Enumerable) {
- return obj;
- }
- if (typeof obj == Types.Number || typeof obj == Types.Boolean) {
- return Enumerable.repeat(obj, 1);
- }
- if (typeof obj == Types.String) {
- return new Enumerable(function () {
- var index = 0;
- return new IEnumerator(
- Functions.Blank,
- function () {
- return (index < obj.length) ? this.yieldReturn(obj.charAt(index++)) : false;
- },
- Functions.Blank);
- });
- }
- if (typeof obj != Types.Function) {
- // array or array like object
- if (typeof obj.length == Types.Number) {
- return new ArrayEnumerable(obj);
- }
-
- // JScript's IEnumerable
- if (!(obj instanceof Object) && Utils.isIEnumerable(obj)) {
- return new Enumerable(function () {
- var isFirst = true;
- var enumerator;
- return new IEnumerator(
- function () { enumerator = new Enumerator(obj); },
- function () {
- if (isFirst) isFirst = false;
- else enumerator.moveNext();
-
- return (enumerator.atEnd()) ? false : this.yieldReturn(enumerator.item());
- },
- Functions.Blank);
- });
- }
-
- // WinMD IIterable<T>
- if (typeof Windows === Types.Object && typeof obj.first === Types.Function) {
- return new Enumerable(function () {
- var isFirst = true;
- var enumerator;
- return new IEnumerator(
- function () { enumerator = obj.first(); },
- function () {
- if (isFirst) isFirst = false;
- else enumerator.moveNext();
-
- return (enumerator.hasCurrent) ? this.yieldReturn(enumerator.current) : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- }
-
- // case function/object : Create keyValuePair[]
- return new Enumerable(function () {
- var array = [];
- var index = 0;
-
- return new IEnumerator(
- function () {
- for (var key in obj) {
- var value = obj[key];
- if (!(value instanceof Function) && Object.prototype.hasOwnProperty.call(obj, key)) {
- array.push({ key: key, value: value });
- }
- }
- },
- function () {
- return (index < array.length)
- ? this.yieldReturn(array[index++])
- : false;
- },
- Functions.Blank);
- });
- },
-
- Enumerable.make = function (element) {
- return Enumerable.repeat(element, 1);
- };
-
- // Overload:function(input, pattern)
- // Overload:function(input, pattern, flags)
- Enumerable.matches = function (input, pattern, flags) {
- if (flags == null) flags = "";
- if (pattern instanceof RegExp) {
- flags += (pattern.ignoreCase) ? "i" : "";
- flags += (pattern.multiline) ? "m" : "";
- pattern = pattern.source;
- }
- if (flags.indexOf("g") === -1) flags += "g";
-
- return new Enumerable(function () {
- var regex;
- return new IEnumerator(
- function () { regex = new RegExp(pattern, flags); },
- function () {
- var match = regex.exec(input);
- return (match) ? this.yieldReturn(match) : false;
- },
- Functions.Blank);
- });
- };
-
- // Overload:function(start, count)
- // Overload:function(start, count, step)
- Enumerable.range = function (start, count, step) {
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- var index = 0;
-
- return new IEnumerator(
- function () { value = start - step; },
- function () {
- return (index++ < count)
- ? this.yieldReturn(value += step)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- // Overload:function(start, count)
- // Overload:function(start, count, step)
- Enumerable.rangeDown = function (start, count, step) {
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- var index = 0;
-
- return new IEnumerator(
- function () { value = start + step; },
- function () {
- return (index++ < count)
- ? this.yieldReturn(value -= step)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- // Overload:function(start, to)
- // Overload:function(start, to, step)
- Enumerable.rangeTo = function (start, to, step) {
- if (step == null) step = 1;
-
- if (start < to) {
- return new Enumerable(function () {
- var value;
-
- return new IEnumerator(
- function () { value = start - step; },
- function () {
- var next = value += step;
- return (next <= to)
- ? this.yieldReturn(next)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- else {
- return new Enumerable(function () {
- var value;
-
- return new IEnumerator(
- function () { value = start + step; },
- function () {
- var next = value -= step;
- return (next >= to)
- ? this.yieldReturn(next)
- : this.yieldBreak();
- },
- Functions.Blank);
- });
- }
- };
-
- // Overload:function(element)
- // Overload:function(element, count)
- Enumerable.repeat = function (element, count) {
- if (count != null) return Enumerable.repeat(element).take(count);
-
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return this.yieldReturn(element); },
- Functions.Blank);
- });
- };
-
- Enumerable.repeatWithFinalize = function (initializer, finalizer) {
- initializer = Utils.createLambda(initializer);
- finalizer = Utils.createLambda(finalizer);
-
- return new Enumerable(function () {
- var element;
- return new IEnumerator(
- function () { element = initializer(); },
- function () { return this.yieldReturn(element); },
- function () {
- if (element != null) {
- finalizer(element);
- element = null;
- }
- });
- });
- };
-
- // Overload:function(func)
- // Overload:function(func, count)
- Enumerable.generate = function (func, count) {
- if (count != null) return Enumerable.generate(func).take(count);
- func = Utils.createLambda(func);
-
- return new Enumerable(function () {
- return new IEnumerator(
- Functions.Blank,
- function () { return this.yieldReturn(func()); },
- Functions.Blank);
- });
- };
-
- // Overload:function()
- // Overload:function(start)
- // Overload:function(start, step)
- Enumerable.toInfinity = function (start, step) {
- if (start == null) start = 0;
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- return new IEnumerator(
- function () { value = start - step; },
- function () { return this.yieldReturn(value += step); },
- Functions.Blank);
- });
- };
-
- // Overload:function()
- // Overload:function(start)
- // Overload:function(start, step)
- Enumerable.toNegativeInfinity = function (start, step) {
- if (start == null) start = 0;
- if (step == null) step = 1;
-
- return new Enumerable(function () {
- var value;
- return new IEnumerator(
- function () { value = start + step; },
- function () { return this.yieldReturn(value -= step); },
- Functions.Blank);
- });
- };
-
- Enumerable.unfold = function (seed, func) {
- func = Utils.createLambda(func);
-
- return new Enumerable(function () {
- var isFirst = true;
- var value;
- return new IEnumerator(
- Functions.Blank,
- function () {
- if (isFirst) {
- isFirst = false;
- value = seed;
- return this.yieldReturn(value);
- }
- value = func(value);
- return this.yieldReturn(value);
- },
- Functions.Blank);
- });
- };
-
- Enumerable.defer = function (enumerableFactory) {
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = Enumerable.from(enumerableFactory()).getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : this.yieldBreak();
- },
- function () {
- Utils.dispose(enumerator);
- });
- });
- };
-
- // Extension Methods
-
- /* Projection and Filtering Methods */
-
- // Overload:function(func)
- // Overload:function(func, resultSelector<element>)
- // Overload:function(func, resultSelector<element, nestLevel>)
- Enumerable.prototype.traverseBreadthFirst = function (func, resultSelector) {
- var source = this;
- func = Utils.createLambda(func);
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumerator;
- var nestLevel = 0;
- var buffer = [];
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (enumerator.moveNext()) {
- buffer.push(enumerator.current());
- return this.yieldReturn(resultSelector(enumerator.current(), nestLevel));
- }
-
- var next = Enumerable.from(buffer).selectMany(function (x) { return func(x); });
- if (!next.any()) {
- return false;
- }
- else {
- nestLevel++;
- buffer = [];
- Utils.dispose(enumerator);
- enumerator = next.getEnumerator();
- }
- }
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(func)
- // Overload:function(func, resultSelector<element>)
- // Overload:function(func, resultSelector<element, nestLevel>)
- Enumerable.prototype.traverseDepthFirst = function (func, resultSelector) {
- var source = this;
- func = Utils.createLambda(func);
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumeratorStack = [];
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (enumerator.moveNext()) {
- var value = resultSelector(enumerator.current(), enumeratorStack.length);
- enumeratorStack.push(enumerator);
- enumerator = Enumerable.from(func(enumerator.current())).getEnumerator();
- return this.yieldReturn(value);
- }
-
- if (enumeratorStack.length <= 0) return false;
- Utils.dispose(enumerator);
- enumerator = enumeratorStack.pop();
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Enumerable.from(enumeratorStack).forEach(function (s) { s.dispose(); });
- }
- });
- });
- };
-
- Enumerable.prototype.flatten = function () {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var middleEnumerator = null;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (true) {
- if (middleEnumerator != null) {
- if (middleEnumerator.moveNext()) {
- return this.yieldReturn(middleEnumerator.current());
- }
- else {
- middleEnumerator = null;
- }
- }
-
- if (enumerator.moveNext()) {
- if (enumerator.current() instanceof Array) {
- Utils.dispose(middleEnumerator);
- middleEnumerator = Enumerable.from(enumerator.current())
- .selectMany(Functions.Identity)
- .flatten()
- .getEnumerator();
- continue;
- }
- else {
- return this.yieldReturn(enumerator.current());
- }
- }
-
- return false;
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(middleEnumerator);
- }
- });
- });
- };
-
- Enumerable.prototype.pairwise = function (selector) {
- var source = this;
- selector = Utils.createLambda(selector);
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- enumerator.moveNext();
- },
- function () {
- var prev = enumerator.current();
- return (enumerator.moveNext())
- ? this.yieldReturn(selector(prev, enumerator.current()))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(func)
- // Overload:function(seed,func<value,element>)
- Enumerable.prototype.scan = function (seed, func) {
- var isUseSeed;
- if (func == null) {
- func = Utils.createLambda(seed); // arguments[0]
- isUseSeed = false;
- } else {
- func = Utils.createLambda(func);
- isUseSeed = true;
- }
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var value;
- var isFirst = true;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (isFirst) {
- isFirst = false;
- if (!isUseSeed) {
- if (enumerator.moveNext()) {
- return this.yieldReturn(value = enumerator.current());
- }
- }
- else {
- return this.yieldReturn(value = seed);
- }
- }
-
- return (enumerator.moveNext())
- ? this.yieldReturn(value = func(value, enumerator.current()))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(selector<element>)
- // Overload:function(selector<element,index>)
- Enumerable.prototype.select = function (selector) {
- selector = Utils.createLambda(selector);
-
- if (selector.length <= 1) {
- return new WhereSelectEnumerable(this, null, selector);
- }
- else {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(selector(enumerator.current(), index++))
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- }
- };
-
- // Overload:function(collectionSelector<element>)
- // Overload:function(collectionSelector<element,index>)
- // Overload:function(collectionSelector<element>,resultSelector)
- // Overload:function(collectionSelector<element,index>,resultSelector)
- Enumerable.prototype.selectMany = function (collectionSelector, resultSelector) {
- var source = this;
- collectionSelector = Utils.createLambda(collectionSelector);
- if (resultSelector == null) resultSelector = function (a, b) { return b; };
- resultSelector = Utils.createLambda(resultSelector);
-
- return new Enumerable(function () {
- var enumerator;
- var middleEnumerator = undefined;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (middleEnumerator === undefined) {
- if (!enumerator.moveNext()) return false;
- }
- do {
- if (middleEnumerator == null) {
- var middleSeq = collectionSelector(enumerator.current(), index++);
- middleEnumerator = Enumerable.from(middleSeq).getEnumerator();
- }
- if (middleEnumerator.moveNext()) {
- return this.yieldReturn(resultSelector(enumerator.current(), middleEnumerator.current()));
- }
- Utils.dispose(middleEnumerator);
- middleEnumerator = null;
- } while (enumerator.moveNext());
- return false;
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(middleEnumerator);
- }
- });
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.where = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- if (predicate.length <= 1) {
- return new WhereEnumerable(this, predicate);
- }
- else {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate(enumerator.current(), index++)) {
- return this.yieldReturn(enumerator.current());
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- }
- };
-
-
- // Overload:function(selector<element>)
- // Overload:function(selector<element,index>)
- Enumerable.prototype.choose = function (selector) {
- selector = Utils.createLambda(selector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- var result = selector(enumerator.current(), index++);
- if (result != null) {
- return this.yieldReturn(result);
- }
- }
- return this.yieldBreak();
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.ofType = function (type) {
- var typeName;
- switch (type) {
- case Number:
- typeName = Types.Number;
- break;
- case String:
- typeName = Types.String;
- break;
- case Boolean:
- typeName = Types.Boolean;
- break;
- case Function:
- typeName = Types.Function;
- break;
- default:
- typeName = null;
- break;
- }
- return (typeName === null)
- ? this.where(function (x) { return x instanceof type; })
- : this.where(function (x) { return typeof x === typeName; });
- };
-
- // mutiple arguments, last one is selector, others are enumerable
- Enumerable.prototype.zip = function () {
- var args = arguments;
- var selector = Utils.createLambda(arguments[arguments.length - 1]);
-
- var source = this;
- // optimized case:argument is 2
- if (arguments.length == 2) {
- var second = arguments[0];
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var index = 0;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- secondEnumerator = Enumerable.from(second).getEnumerator();
- },
- function () {
- if (firstEnumerator.moveNext() && secondEnumerator.moveNext()) {
- return this.yieldReturn(selector(firstEnumerator.current(), secondEnumerator.current(), index++));
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- } finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- }
- else {
- return new Enumerable(function () {
- var enumerators;
- var index = 0;
-
- return new IEnumerator(
- function () {
- var array = Enumerable.make(source)
- .concat(Enumerable.from(args).takeExceptLast().select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- enumerators = Enumerable.from(array);
- },
- function () {
- if (enumerators.all(function (x) { return x.moveNext() })) {
- var array = enumerators
- .select(function (x) { return x.current() })
- .toArray();
- array.push(index++);
- return this.yieldReturn(selector.apply(null, array));
- }
- else {
- return this.yieldBreak();
- }
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- }
- };
-
- // mutiple arguments
- Enumerable.prototype.merge = function () {
- var args = arguments;
- var source = this;
-
- return new Enumerable(function () {
- var enumerators;
- var index = -1;
-
- return new IEnumerator(
- function () {
- enumerators = Enumerable.make(source)
- .concat(Enumerable.from(args).select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- },
- function () {
- while (enumerators.length > 0) {
- index = (index >= enumerators.length - 1) ? 0 : index + 1;
- var enumerator = enumerators[index];
-
- if (enumerator.moveNext()) {
- return this.yieldReturn(enumerator.current());
- }
- else {
- enumerator.dispose();
- enumerators.splice(index--, 1);
- }
- }
- return this.yieldBreak();
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- };
-
- /* Join Methods */
-
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector)
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector)
- Enumerable.prototype.join = function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
- outerKeySelector = Utils.createLambda(outerKeySelector);
- innerKeySelector = Utils.createLambda(innerKeySelector);
- resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var outerEnumerator;
- var lookup;
- var innerElements = null;
- var innerCount = 0;
-
- return new IEnumerator(
- function () {
- outerEnumerator = source.getEnumerator();
- lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
- },
- function () {
- while (true) {
- if (innerElements != null) {
- var innerElement = innerElements[innerCount++];
- if (innerElement !== undefined) {
- return this.yieldReturn(resultSelector(outerEnumerator.current(), innerElement));
- }
-
- innerElement = null;
- innerCount = 0;
- }
-
- if (outerEnumerator.moveNext()) {
- var key = outerKeySelector(outerEnumerator.current());
- innerElements = lookup.get(key).toArray();
- } else {
- return false;
- }
- }
- },
- function () { Utils.dispose(outerEnumerator); });
- });
- };
-
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector)
- // Overload:function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector)
- Enumerable.prototype.groupJoin = function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
- outerKeySelector = Utils.createLambda(outerKeySelector);
- innerKeySelector = Utils.createLambda(innerKeySelector);
- resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator = source.getEnumerator();
- var lookup = null;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
- },
- function () {
- if (enumerator.moveNext()) {
- var innerElement = lookup.get(outerKeySelector(enumerator.current()));
- return this.yieldReturn(resultSelector(enumerator.current(), innerElement));
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- /* Set Methods */
-
- Enumerable.prototype.all = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- var result = true;
- this.forEach(function (x) {
- if (!predicate(x)) {
- result = false;
- return false; // break
- }
- });
- return result;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.any = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- var enumerator = this.getEnumerator();
- try {
- if (arguments.length == 0) return enumerator.moveNext(); // case:function()
-
- while (enumerator.moveNext()) // case:function(predicate)
- {
- if (predicate(enumerator.current())) return true;
- }
- return false;
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- Enumerable.prototype.isEmpty = function () {
- return !this.any();
- };
-
- // multiple arguments
- Enumerable.prototype.concat = function () {
- var source = this;
-
- if (arguments.length == 1) {
- var second = arguments[0];
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
-
- return new IEnumerator(
- function () { firstEnumerator = source.getEnumerator(); },
- function () {
- if (secondEnumerator == null) {
- if (firstEnumerator.moveNext()) return this.yieldReturn(firstEnumerator.current());
- secondEnumerator = Enumerable.from(second).getEnumerator();
- }
- if (secondEnumerator.moveNext()) return this.yieldReturn(secondEnumerator.current());
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- }
- else {
- var args = arguments;
-
- return new Enumerable(function () {
- var enumerators;
-
- return new IEnumerator(
- function () {
- enumerators = Enumerable.make(source)
- .concat(Enumerable.from(args).select(Enumerable.from))
- .select(function (x) { return x.getEnumerator() })
- .toArray();
- },
- function () {
- while (enumerators.length > 0) {
- var enumerator = enumerators[0];
-
- if (enumerator.moveNext()) {
- return this.yieldReturn(enumerator.current());
- }
- else {
- enumerator.dispose();
- enumerators.splice(0, 1);
- }
- }
- return this.yieldBreak();
- },
- function () {
- Enumerable.from(enumerators).forEach(Utils.dispose);
- });
- });
- }
- };
-
- Enumerable.prototype.insert = function (index, second) {
- var source = this;
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var count = 0;
- var isEnumerated = false;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- secondEnumerator = Enumerable.from(second).getEnumerator();
- },
- function () {
- if (count == index && secondEnumerator.moveNext()) {
- isEnumerated = true;
- return this.yieldReturn(secondEnumerator.current());
- }
- if (firstEnumerator.moveNext()) {
- count++;
- return this.yieldReturn(firstEnumerator.current());
- }
- if (!isEnumerated && secondEnumerator.moveNext()) {
- return this.yieldReturn(secondEnumerator.current());
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- };
-
- Enumerable.prototype.alternate = function (alternateValueOrSequence) {
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
- var enumerator;
- var alternateSequence;
- var alternateEnumerator;
-
- return new IEnumerator(
- function () {
- if (alternateValueOrSequence instanceof Array || alternateValueOrSequence.getEnumerator != null) {
- alternateSequence = Enumerable.from(Enumerable.from(alternateValueOrSequence).toArray()); // freeze
- }
- else {
- alternateSequence = Enumerable.make(alternateValueOrSequence);
- }
- enumerator = source.getEnumerator();
- if (enumerator.moveNext()) buffer = enumerator.current();
- },
- function () {
- while (true) {
- if (alternateEnumerator != null) {
- if (alternateEnumerator.moveNext()) {
- return this.yieldReturn(alternateEnumerator.current());
- }
- else {
- alternateEnumerator = null;
- }
- }
-
- if (buffer == null && enumerator.moveNext()) {
- buffer = enumerator.current(); // hasNext
- alternateEnumerator = alternateSequence.getEnumerator();
- continue; // GOTO
- }
- else if (buffer != null) {
- var retVal = buffer;
- buffer = null;
- return this.yieldReturn(retVal);
- }
-
- return this.yieldBreak();
- }
- },
- function () {
- try {
- Utils.dispose(enumerator);
- }
- finally {
- Utils.dispose(alternateEnumerator);
- }
- });
- });
- };
-
- // Overload:function(value)
- // Overload:function(value, compareSelector)
- Enumerable.prototype.contains = function (value, compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
- var enumerator = this.getEnumerator();
- try {
- while (enumerator.moveNext()) {
- if (compareSelector(enumerator.current()) === value) return true;
- }
- return false;
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- Enumerable.prototype.defaultIfEmpty = function (defaultValue) {
- var source = this;
- if (defaultValue === undefined) defaultValue = null;
-
- return new Enumerable(function () {
- var enumerator;
- var isFirst = true;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (enumerator.moveNext()) {
- isFirst = false;
- return this.yieldReturn(enumerator.current());
- }
- else if (isFirst) {
- isFirst = false;
- return this.yieldReturn(defaultValue);
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function()
- // Overload:function(compareSelector)
- Enumerable.prototype.distinct = function (compareSelector) {
- return this.except(Enumerable.empty(), compareSelector);
- };
-
- Enumerable.prototype.distinctUntilChanged = function (compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var compareKey;
- var initial;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- },
- function () {
- while (enumerator.moveNext()) {
- var key = compareSelector(enumerator.current());
-
- if (initial) {
- initial = false;
- compareKey = key;
- return this.yieldReturn(enumerator.current());
- }
-
- if (compareKey === key) {
- continue;
- }
-
- compareKey = key;
- return this.yieldReturn(enumerator.current());
- }
- return this.yieldBreak();
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.except = function (second, compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var keys;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- keys = new Dictionary(compareSelector);
- Enumerable.from(second).forEach(function (key) { keys.add(key); });
- },
- function () {
- while (enumerator.moveNext()) {
- var current = enumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.intersect = function (second, compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var keys;
- var outs;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
-
- keys = new Dictionary(compareSelector);
- Enumerable.from(second).forEach(function (key) { keys.add(key); });
- outs = new Dictionary(compareSelector);
- },
- function () {
- while (enumerator.moveNext()) {
- var current = enumerator.current();
- if (!outs.contains(current) && keys.contains(current)) {
- outs.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(second)
- // Overload:function(second, compareSelector)
- Enumerable.prototype.sequenceEqual = function (second, compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
-
- var firstEnumerator = this.getEnumerator();
- try {
- var secondEnumerator = Enumerable.from(second).getEnumerator();
- try {
- while (firstEnumerator.moveNext()) {
- if (!secondEnumerator.moveNext()
- || compareSelector(firstEnumerator.current()) !== compareSelector(secondEnumerator.current())) {
- return false;
- }
- }
-
- if (secondEnumerator.moveNext()) return false;
- return true;
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- }
- finally {
- Utils.dispose(firstEnumerator);
- }
- };
-
- Enumerable.prototype.union = function (second, compareSelector) {
- compareSelector = Utils.createLambda(compareSelector);
- var source = this;
-
- return new Enumerable(function () {
- var firstEnumerator;
- var secondEnumerator;
- var keys;
-
- return new IEnumerator(
- function () {
- firstEnumerator = source.getEnumerator();
- keys = new Dictionary(compareSelector);
- },
- function () {
- var current;
- if (secondEnumerator === undefined) {
- while (firstEnumerator.moveNext()) {
- current = firstEnumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- secondEnumerator = Enumerable.from(second).getEnumerator();
- }
- while (secondEnumerator.moveNext()) {
- current = secondEnumerator.current();
- if (!keys.contains(current)) {
- keys.add(current);
- return this.yieldReturn(current);
- }
- }
- return false;
- },
- function () {
- try {
- Utils.dispose(firstEnumerator);
- }
- finally {
- Utils.dispose(secondEnumerator);
- }
- });
- });
- };
-
- /* Ordering Methods */
-
- Enumerable.prototype.orderBy = function (keySelector) {
- return new OrderedEnumerable(this, keySelector, false);
- };
-
- Enumerable.prototype.orderByDescending = function (keySelector) {
- return new OrderedEnumerable(this, keySelector, true);
- };
-
- Enumerable.prototype.reverse = function () {
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
- var index;
-
- return new IEnumerator(
- function () {
- buffer = source.toArray();
- index = buffer.length;
- },
- function () {
- return (index > 0)
- ? this.yieldReturn(buffer[--index])
- : false;
- },
- Functions.Blank);
- });
- };
-
- Enumerable.prototype.shuffle = function () {
- var source = this;
-
- return new Enumerable(function () {
- var buffer;
-
- return new IEnumerator(
- function () { buffer = source.toArray(); },
- function () {
- if (buffer.length > 0) {
- var i = Math.floor(Math.random() * buffer.length);
- return this.yieldReturn(buffer.splice(i, 1)[0]);
- }
- return false;
- },
- Functions.Blank);
- });
- };
-
- Enumerable.prototype.weightedSample = function (weightSelector) {
- weightSelector = Utils.createLambda(weightSelector);
- var source = this;
-
- return new Enumerable(function () {
- var sortedByBound;
- var totalWeight = 0;
-
- return new IEnumerator(
- function () {
- sortedByBound = source
- .choose(function (x) {
- var weight = weightSelector(x);
- if (weight <= 0) return null; // ignore 0
-
- totalWeight += weight;
- return { value: x, bound: totalWeight };
- })
- .toArray();
- },
- function () {
- if (sortedByBound.length > 0) {
- var draw = Math.floor(Math.random() * totalWeight) + 1;
-
- var lower = -1;
- var upper = sortedByBound.length;
- while (upper - lower > 1) {
- var index = Math.floor((lower + upper) / 2);
- if (sortedByBound[index].bound >= draw) {
- upper = index;
- }
- else {
- lower = index;
- }
- }
-
- return this.yieldReturn(sortedByBound[upper].value);
- }
-
- return this.yieldBreak();
- },
- Functions.Blank);
- });
- };
-
- /* Grouping Methods */
-
- // Overload:function(keySelector)
- // Overload:function(keySelector,elementSelector)
- // Overload:function(keySelector,elementSelector,resultSelector)
- // Overload:function(keySelector,elementSelector,resultSelector,compareSelector)
- Enumerable.prototype.groupBy = function (keySelector, elementSelector, resultSelector, compareSelector) {
- var source = this;
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- if (resultSelector != null) resultSelector = Utils.createLambda(resultSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = source.toLookup(keySelector, elementSelector, compareSelector)
- .toEnumerable()
- .getEnumerator();
- },
- function () {
- while (enumerator.moveNext()) {
- return (resultSelector == null)
- ? this.yieldReturn(enumerator.current())
- : this.yieldReturn(resultSelector(enumerator.current().key(), enumerator.current()));
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(keySelector)
- // Overload:function(keySelector,elementSelector)
- // Overload:function(keySelector,elementSelector,resultSelector)
- // Overload:function(keySelector,elementSelector,resultSelector,compareSelector)
- Enumerable.prototype.partitionBy = function (keySelector, elementSelector, resultSelector, compareSelector) {
-
- var source = this;
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
- var hasResultSelector;
- if (resultSelector == null) {
- hasResultSelector = false;
- resultSelector = function (key, group) { return new Grouping(key, group); };
- }
- else {
- hasResultSelector = true;
- resultSelector = Utils.createLambda(resultSelector);
- }
-
- return new Enumerable(function () {
- var enumerator;
- var key;
- var compareKey;
- var group = [];
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- if (enumerator.moveNext()) {
- key = keySelector(enumerator.current());
- compareKey = compareSelector(key);
- group.push(elementSelector(enumerator.current()));
- }
- },
- function () {
- var hasNext;
- while ((hasNext = enumerator.moveNext()) == true) {
- if (compareKey === compareSelector(keySelector(enumerator.current()))) {
- group.push(elementSelector(enumerator.current()));
- }
- else break;
- }
-
- if (group.length > 0) {
- var result = (hasResultSelector)
- ? resultSelector(key, Enumerable.from(group))
- : resultSelector(key, group);
- if (hasNext) {
- key = keySelector(enumerator.current());
- compareKey = compareSelector(key);
- group = [elementSelector(enumerator.current())];
- }
- else group = [];
-
- return this.yieldReturn(result);
- }
-
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.buffer = function (count) {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- var array = [];
- var index = 0;
- while (enumerator.moveNext()) {
- array.push(enumerator.current());
- if (++index >= count) return this.yieldReturn(array);
- }
- if (array.length > 0) return this.yieldReturn(array);
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- /* Aggregate Methods */
-
- // Overload:function(func)
- // Overload:function(seed,func)
- // Overload:function(seed,func,resultSelector)
- Enumerable.prototype.aggregate = function (seed, func, resultSelector) {
- resultSelector = Utils.createLambda(resultSelector);
- return resultSelector(this.scan(seed, func, resultSelector).last());
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.average = function (selector) {
- selector = Utils.createLambda(selector);
-
- var sum = 0;
- var count = 0;
- this.forEach(function (x) {
- sum += selector(x);
- ++count;
- });
-
- return sum / count;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.count = function (predicate) {
- predicate = (predicate == null) ? Functions.True : Utils.createLambda(predicate);
-
- var count = 0;
- this.forEach(function (x, i) {
- if (predicate(x, i))++count;
- });
- return count;
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.max = function (selector) {
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(function (a, b) { return (a > b) ? a : b; });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.min = function (selector) {
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(function (a, b) { return (a < b) ? a : b; });
- };
-
- Enumerable.prototype.maxBy = function (keySelector) {
- keySelector = Utils.createLambda(keySelector);
- return this.aggregate(function (a, b) { return (keySelector(a) > keySelector(b)) ? a : b; });
- };
-
- Enumerable.prototype.minBy = function (keySelector) {
- keySelector = Utils.createLambda(keySelector);
- return this.aggregate(function (a, b) { return (keySelector(a) < keySelector(b)) ? a : b; });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.sum = function (selector) {
- if (selector == null) selector = Functions.Identity;
- return this.select(selector).aggregate(0, function (a, b) { return a + b; });
- };
-
- /* Paging Methods */
-
- Enumerable.prototype.elementAt = function (index) {
- var value;
- var found = false;
- this.forEach(function (x, i) {
- if (i == index) {
- value = x;
- found = true;
- return false;
- }
- });
-
- if (!found) throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");
- return value;
- };
-
- Enumerable.prototype.elementAtOrDefault = function (index, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- var value;
- var found = false;
- this.forEach(function (x, i) {
- if (i == index) {
- value = x;
- found = true;
- return false;
- }
- });
-
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.first = function (predicate) {
- if (predicate != null) return this.where(predicate).first();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- value = x;
- found = true;
- return false;
- });
-
- if (!found) throw new Error("first:No element satisfies the condition.");
- return value;
- };
-
- Enumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).firstOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- value = x;
- found = true;
- return false;
- });
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.last = function (predicate) {
- if (predicate != null) return this.where(predicate).last();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- found = true;
- value = x;
- });
-
- if (!found) throw new Error("last:No element satisfies the condition.");
- return value;
- };
-
- // Overload:function(defaultValue)
- // Overload:function(defaultValue,predicate)
- Enumerable.prototype.lastOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).lastOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- found = true;
- value = x;
- });
- return (!found) ? defaultValue : value;
- };
-
- // Overload:function()
- // Overload:function(predicate)
- Enumerable.prototype.single = function (predicate) {
- if (predicate != null) return this.where(predicate).single();
-
- var value;
- var found = false;
- this.forEach(function (x) {
- if (!found) {
- found = true;
- value = x;
- } else throw new Error("single:sequence contains more than one element.");
- });
-
- if (!found) throw new Error("single:No element satisfies the condition.");
- return value;
- };
-
- // Overload:function(defaultValue)
- // Overload:function(defaultValue,predicate)
- Enumerable.prototype.singleOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) return this.where(predicate).singleOrDefault(null, defaultValue);
-
- var value;
- var found = false;
- this.forEach(function (x) {
- if (!found) {
- found = true;
- value = x;
- } else throw new Error("single:sequence contains more than one element.");
- });
-
- return (!found) ? defaultValue : value;
- };
-
- Enumerable.prototype.skip = function (count) {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () {
- enumerator = source.getEnumerator();
- while (index++ < count && enumerator.moveNext()) {
- }
- ;
- },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.skipWhile = function (predicate) {
- predicate = Utils.createLambda(predicate);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
- var isSkipEnd = false;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (!isSkipEnd) {
- if (enumerator.moveNext()) {
- if (!predicate(enumerator.current(), index++)) {
- isSkipEnd = true;
- return this.yieldReturn(enumerator.current());
- }
- continue;
- } else return false;
- }
-
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
-
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.take = function (count) {
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (index++ < count && enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); }
- );
- });
- };
-
- // Overload:function(predicate<element>)
- // Overload:function(predicate<element,index>)
- Enumerable.prototype.takeWhile = function (predicate) {
- predicate = Utils.createLambda(predicate);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext() && predicate(enumerator.current(), index++))
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function()
- // Overload:function(count)
- Enumerable.prototype.takeExceptLast = function (count) {
- if (count == null) count = 1;
- var source = this;
-
- return new Enumerable(function () {
- if (count <= 0) return source.getEnumerator(); // do nothing
-
- var enumerator;
- var q = [];
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (q.length == count) {
- q.push(enumerator.current());
- return this.yieldReturn(q.shift());
- }
- q.push(enumerator.current());
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.takeFromLast = function (count) {
- if (count <= 0 || count == null) return Enumerable.empty();
- var source = this;
-
- return new Enumerable(function () {
- var sourceEnumerator;
- var enumerator;
- var q = [];
-
- return new IEnumerator(
- function () { sourceEnumerator = source.getEnumerator(); },
- function () {
- while (sourceEnumerator.moveNext()) {
- if (q.length == count) q.shift();
- q.push(sourceEnumerator.current());
- }
- if (enumerator == null) {
- enumerator = Enumerable.from(q).getEnumerator();
- }
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(item)
- // Overload:function(predicate)
- Enumerable.prototype.indexOf = function (item) {
- var found = null;
-
- // item as predicate
- if (typeof (item) === Types.Function) {
- this.forEach(function (x, i) {
- if (item(x, i)) {
- found = i;
- return false;
- }
- });
- }
- else {
- this.forEach(function (x, i) {
- if (x === item) {
- found = i;
- return false;
- }
- });
- }
-
- return (found !== null) ? found : -1;
- };
-
- // Overload:function(item)
- // Overload:function(predicate)
- Enumerable.prototype.lastIndexOf = function (item) {
- var result = -1;
-
- // item as predicate
- if (typeof (item) === Types.Function) {
- this.forEach(function (x, i) {
- if (item(x, i)) result = i;
- });
- }
- else {
- this.forEach(function (x, i) {
- if (x === item) result = i;
- });
- }
-
- return result;
- };
-
- /* Convert Methods */
-
- Enumerable.prototype.cast = function () {
- return this;
- };
-
- Enumerable.prototype.asEnumerable = function () {
- return Enumerable.from(this);
- };
-
- Enumerable.prototype.toArray = function () {
- var array = [];
- this.forEach(function (x) { array.push(x); });
- return array;
- };
-
- // Overload:function(keySelector)
- // Overload:function(keySelector, elementSelector)
- // Overload:function(keySelector, elementSelector, compareSelector)
- Enumerable.prototype.toLookup = function (keySelector, elementSelector, compareSelector) {
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- var dict = new Dictionary(compareSelector);
- this.forEach(function (x) {
- var key = keySelector(x);
- var element = elementSelector(x);
-
- var array = dict.get(key);
- if (array !== undefined) array.push(element);
- else dict.add(key, [element]);
- });
- return new Lookup(dict);
- };
-
- Enumerable.prototype.toObject = function (keySelector, elementSelector) {
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
-
- var obj = {};
- this.forEach(function (x) {
- obj[keySelector(x)] = elementSelector(x);
- });
- return obj;
- };
-
- // Overload:function(keySelector, elementSelector)
- // Overload:function(keySelector, elementSelector, compareSelector)
- Enumerable.prototype.toDictionary = function (keySelector, elementSelector, compareSelector) {
- keySelector = Utils.createLambda(keySelector);
- elementSelector = Utils.createLambda(elementSelector);
- compareSelector = Utils.createLambda(compareSelector);
-
- var dict = new Dictionary(compareSelector);
- this.forEach(function (x) {
- dict.add(keySelector(x), elementSelector(x));
- });
- return dict;
- };
-
- // Overload:function()
- // Overload:function(replacer)
- // Overload:function(replacer, space)
- Enumerable.prototype.toJSONString = function (replacer, space) {
- if (typeof JSON === Types.Undefined || JSON.stringify == null) {
- throw new Error("toJSONString can't find JSON.stringify. This works native JSON support Browser or include json2.js");
- }
- return JSON.stringify(this.toArray(), replacer, space);
- };
-
- // Overload:function()
- // Overload:function(separator)
- // Overload:function(separator,selector)
- Enumerable.prototype.toJoinedString = function (separator, selector) {
- if (separator == null) separator = "";
- if (selector == null) selector = Functions.Identity;
-
- return this.select(selector).toArray().join(separator);
- };
-
-
- /* Action Methods */
-
- // Overload:function(action<element>)
- // Overload:function(action<element,index>)
- Enumerable.prototype.doAction = function (action) {
- var source = this;
- action = Utils.createLambda(action);
-
- return new Enumerable(function () {
- var enumerator;
- var index = 0;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- if (enumerator.moveNext()) {
- action(enumerator.current(), index++);
- return this.yieldReturn(enumerator.current());
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- // Overload:function(action<element>)
- // Overload:function(action<element,index>)
- // Overload:function(func<element,bool>)
- // Overload:function(func<element,index,bool>)
- Enumerable.prototype.forEach = function (action) {
- action = Utils.createLambda(action);
-
- var index = 0;
- var enumerator = this.getEnumerator();
- try {
- while (enumerator.moveNext()) {
- if (action(enumerator.current(), index++) === false) break;
- }
- } finally {
- Utils.dispose(enumerator);
- }
- };
-
- // Overload:function()
- // Overload:function(separator)
- // Overload:function(separator,selector)
- Enumerable.prototype.write = function (separator, selector) {
- if (separator == null) separator = "";
- selector = Utils.createLambda(selector);
-
- var isFirst = true;
- this.forEach(function (item) {
- if (isFirst) isFirst = false;
- else document.write(separator);
- document.write(selector(item));
- });
- };
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.writeLine = function (selector) {
- selector = Utils.createLambda(selector);
-
- this.forEach(function (item) {
- document.writeln(selector(item) + "<br />");
- });
- };
-
- Enumerable.prototype.force = function () {
- var enumerator = this.getEnumerator();
-
- try {
- while (enumerator.moveNext()) {
- }
- }
- finally {
- Utils.dispose(enumerator);
- }
- };
-
- /* Functional Methods */
-
- Enumerable.prototype.letBind = function (func) {
- func = Utils.createLambda(func);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () {
- enumerator = Enumerable.from(func(source)).getEnumerator();
- },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.share = function () {
- var source = this;
- var sharedEnumerator;
- var disposed = false;
-
- return new DisposableEnumerable(function () {
- return new IEnumerator(
- function () {
- if (sharedEnumerator == null) {
- sharedEnumerator = source.getEnumerator();
- }
- },
- function () {
- if (disposed) throw new Error("enumerator is disposed");
-
- return (sharedEnumerator.moveNext())
- ? this.yieldReturn(sharedEnumerator.current())
- : false;
- },
- Functions.Blank
- );
- }, function () {
- disposed = true;
- Utils.dispose(sharedEnumerator);
- });
- };
-
- Enumerable.prototype.memoize = function () {
- var source = this;
- var cache;
- var enumerator;
- var disposed = false;
-
- return new DisposableEnumerable(function () {
- var index = -1;
-
- return new IEnumerator(
- function () {
- if (enumerator == null) {
- enumerator = source.getEnumerator();
- cache = [];
- }
- },
- function () {
- if (disposed) throw new Error("enumerator is disposed");
-
- index++;
- if (cache.length <= index) {
- return (enumerator.moveNext())
- ? this.yieldReturn(cache[index] = enumerator.current())
- : false;
- }
-
- return this.yieldReturn(cache[index]);
- },
- Functions.Blank
- );
- }, function () {
- disposed = true;
- Utils.dispose(enumerator);
- cache = null;
- });
- };
-
- /* Error Handling Methods */
-
- Enumerable.prototype.catchError = function (handler) {
- handler = Utils.createLambda(handler);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- try {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- } catch (e) {
- handler(e);
- return false;
- }
- },
- function () { Utils.dispose(enumerator); });
- });
- };
-
- Enumerable.prototype.finallyAction = function (finallyAction) {
- finallyAction = Utils.createLambda(finallyAction);
- var source = this;
-
- return new Enumerable(function () {
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : false;
- },
- function () {
- try {
- Utils.dispose(enumerator);
- } finally {
- finallyAction();
- }
- });
- });
- };
-
- /* For Debug Methods */
-
- // Overload:function()
- // Overload:function(selector)
- Enumerable.prototype.log = function (selector) {
- selector = Utils.createLambda(selector);
-
- return this.doAction(function (item) {
- if (typeof console !== Types.Undefined) {
- console.log(selector(item));
- }
- });
- };
-
- // Overload:function()
- // Overload:function(message)
- // Overload:function(message,selector)
- Enumerable.prototype.trace = function (message, selector) {
- if (message == null) message = "Trace";
- selector = Utils.createLambda(selector);
-
- return this.doAction(function (item) {
- if (typeof console !== Types.Undefined) {
- console.log(message, selector(item));
- }
- });
- };
-
- // private
-
- var OrderedEnumerable = function (source, keySelector, descending, parent) {
- this.source = source;
- this.keySelector = Utils.createLambda(keySelector);
- this.descending = descending;
- this.parent = parent;
- };
- OrderedEnumerable.prototype = new Enumerable();
-
- OrderedEnumerable.prototype.createOrderedEnumerable = function (keySelector, descending) {
- return new OrderedEnumerable(this.source, keySelector, descending, this);
- };
-
- OrderedEnumerable.prototype.thenBy = function (keySelector) {
- return this.createOrderedEnumerable(keySelector, false);
- };
-
- OrderedEnumerable.prototype.thenByDescending = function (keySelector) {
- return this.createOrderedEnumerable(keySelector, true);
- };
-
- OrderedEnumerable.prototype.getEnumerator = function () {
- var self = this;
- var buffer;
- var indexes;
- var index = 0;
-
- return new IEnumerator(
- function () {
- buffer = [];
- indexes = [];
- self.source.forEach(function (item, index) {
- buffer.push(item);
- indexes.push(index);
- });
- var sortContext = SortContext.create(self, null);
- sortContext.GenerateKeys(buffer);
-
- indexes.sort(function (a, b) { return sortContext.compare(a, b); });
- },
- function () {
- return (index < indexes.length)
- ? this.yieldReturn(buffer[indexes[index++]])
- : false;
- },
- Functions.Blank
- );
- };
-
- var SortContext = function (keySelector, descending, child) {
- this.keySelector = keySelector;
- this.descending = descending;
- this.child = child;
- this.keys = null;
- };
-
- SortContext.create = function (orderedEnumerable, currentContext) {
- var context = new SortContext(orderedEnumerable.keySelector, orderedEnumerable.descending, currentContext);
- if (orderedEnumerable.parent != null) return SortContext.create(orderedEnumerable.parent, context);
- return context;
- };
-
- SortContext.prototype.GenerateKeys = function (source) {
- var len = source.length;
- var keySelector = this.keySelector;
- var keys = new Array(len);
- for (var i = 0; i < len; i++) keys[i] = keySelector(source[i]);
- this.keys = keys;
-
- if (this.child != null) this.child.GenerateKeys(source);
- };
-
- SortContext.prototype.compare = function (index1, index2) {
- var comparison = Utils.compare(this.keys[index1], this.keys[index2]);
-
- if (comparison == 0) {
- if (this.child != null) return this.child.compare(index1, index2);
- return Utils.compare(index1, index2);
- }
-
- return (this.descending) ? -comparison : comparison;
- };
-
- var DisposableEnumerable = function (getEnumerator, dispose) {
- this.dispose = dispose;
- Enumerable.call(this, getEnumerator);
- };
- DisposableEnumerable.prototype = new Enumerable();
-
- // optimize array or arraylike object
-
- var ArrayEnumerable = function (source) {
- this.getSource = function () { return source; };
- };
- ArrayEnumerable.prototype = new Enumerable();
-
- ArrayEnumerable.prototype.any = function (predicate) {
- return (predicate == null)
- ? (this.getSource().length > 0)
- : Enumerable.prototype.any.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.count = function (predicate) {
- return (predicate == null)
- ? this.getSource().length
- : Enumerable.prototype.count.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.elementAt = function (index) {
- var source = this.getSource();
- return (0 <= index && index < source.length)
- ? source[index]
- : Enumerable.prototype.elementAt.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.elementAtOrDefault = function (index, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- var source = this.getSource();
- return (0 <= index && index < source.length)
- ? source[index]
- : defaultValue;
- };
-
- ArrayEnumerable.prototype.first = function (predicate) {
- var source = this.getSource();
- return (predicate == null && source.length > 0)
- ? source[0]
- : Enumerable.prototype.first.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.firstOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) {
- return Enumerable.prototype.firstOrDefault.apply(this, arguments);
- }
-
- var source = this.getSource();
- return source.length > 0 ? source[0] : defaultValue;
- };
-
- ArrayEnumerable.prototype.last = function (predicate) {
- var source = this.getSource();
- return (predicate == null && source.length > 0)
- ? source[source.length - 1]
- : Enumerable.prototype.last.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.lastOrDefault = function (predicate, defaultValue) {
- if (defaultValue === undefined) defaultValue = null;
- if (predicate != null) {
- return Enumerable.prototype.lastOrDefault.apply(this, arguments);
- }
-
- var source = this.getSource();
- return source.length > 0 ? source[source.length - 1] : defaultValue;
- };
-
- ArrayEnumerable.prototype.skip = function (count) {
- var source = this.getSource();
-
- return new Enumerable(function () {
- var index;
-
- return new IEnumerator(
- function () { index = (count < 0) ? 0 : count; },
- function () {
- return (index < source.length)
- ? this.yieldReturn(source[index++])
- : false;
- },
- Functions.Blank);
- });
- };
-
- ArrayEnumerable.prototype.takeExceptLast = function (count) {
- if (count == null) count = 1;
- return this.take(this.getSource().length - count);
- };
-
- ArrayEnumerable.prototype.takeFromLast = function (count) {
- return this.skip(this.getSource().length - count);
- };
-
- ArrayEnumerable.prototype.reverse = function () {
- var source = this.getSource();
-
- return new Enumerable(function () {
- var index;
-
- return new IEnumerator(
- function () {
- index = source.length;
- },
- function () {
- return (index > 0)
- ? this.yieldReturn(source[--index])
- : false;
- },
- Functions.Blank);
- });
- };
-
- ArrayEnumerable.prototype.sequenceEqual = function (second, compareSelector) {
- if ((second instanceof ArrayEnumerable || second instanceof Array)
- && compareSelector == null
- && Enumerable.from(second).count() != this.count()) {
- return false;
- }
-
- return Enumerable.prototype.sequenceEqual.apply(this, arguments);
- };
-
- ArrayEnumerable.prototype.toJoinedString = function (separator, selector) {
- var source = this.getSource();
- if (selector != null || !(source instanceof Array)) {
- return Enumerable.prototype.toJoinedString.apply(this, arguments);
- }
-
- if (separator == null) separator = "";
- return source.join(separator);
- };
-
- ArrayEnumerable.prototype.getEnumerator = function () {
- var source = this.getSource();
- var index = -1;
-
- // fast and simple enumerator
- return {
- current: function () { return source[index]; },
- moveNext: function () {
- return ++index < source.length;
- },
- dispose: Functions.Blank
- };
- };
-
- // optimization for multiple where and multiple select and whereselect
-
- var WhereEnumerable = function (source, predicate) {
- this.prevSource = source;
- this.prevPredicate = predicate; // predicate.length always <= 1
- };
- WhereEnumerable.prototype = new Enumerable();
-
- WhereEnumerable.prototype.where = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- if (predicate.length <= 1) {
- var prevPredicate = this.prevPredicate;
- var composedPredicate = function (x) { return prevPredicate(x) && predicate(x); };
- return new WhereEnumerable(this.prevSource, composedPredicate);
- }
- else {
- // if predicate use index, can't compose
- return Enumerable.prototype.where.call(this, predicate);
- }
- };
-
- WhereEnumerable.prototype.select = function (selector) {
- selector = Utils.createLambda(selector);
-
- return (selector.length <= 1)
- ? new WhereSelectEnumerable(this.prevSource, this.prevPredicate, selector)
- : Enumerable.prototype.select.call(this, selector);
- };
-
- WhereEnumerable.prototype.getEnumerator = function () {
- var predicate = this.prevPredicate;
- var source = this.prevSource;
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate(enumerator.current())) {
- return this.yieldReturn(enumerator.current());
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- };
-
- var WhereSelectEnumerable = function (source, predicate, selector) {
- this.prevSource = source;
- this.prevPredicate = predicate; // predicate.length always <= 1 or null
- this.prevSelector = selector; // selector.length always <= 1
- };
- WhereSelectEnumerable.prototype = new Enumerable();
-
- WhereSelectEnumerable.prototype.where = function (predicate) {
- predicate = Utils.createLambda(predicate);
-
- return (predicate.length <= 1)
- ? new WhereEnumerable(this, predicate)
- : Enumerable.prototype.where.call(this, predicate);
- };
-
- WhereSelectEnumerable.prototype.select = function (selector) {
- selector = Utils.createLambda(selector);
-
- if (selector.length <= 1) {
- var prevSelector = this.prevSelector;
- var composedSelector = function (x) { return selector(prevSelector(x)); };
- return new WhereSelectEnumerable(this.prevSource, this.prevPredicate, composedSelector);
- }
- else {
- // if selector use index, can't compose
- return Enumerable.prototype.select.call(this, selector);
- }
- };
-
- WhereSelectEnumerable.prototype.getEnumerator = function () {
- var predicate = this.prevPredicate;
- var selector = this.prevSelector;
- var source = this.prevSource;
- var enumerator;
-
- return new IEnumerator(
- function () { enumerator = source.getEnumerator(); },
- function () {
- while (enumerator.moveNext()) {
- if (predicate == null || predicate(enumerator.current())) {
- return this.yieldReturn(selector(enumerator.current()));
- }
- }
- return false;
- },
- function () { Utils.dispose(enumerator); });
- };
-
- // Collections
-
- var Dictionary = (function () {
- // static utility methods
- var callHasOwnProperty = function (target, key) {
- return Object.prototype.hasOwnProperty.call(target, key);
- };
-
- var computeHashCode = function (obj) {
- if (obj === null) return "null";
- if (obj === undefined) return "undefined";
-
- return (typeof obj.toString === Types.Function)
- ? obj.toString()
- : Object.prototype.toString.call(obj);
- };
-
- // LinkedList for Dictionary
- var HashEntry = function (key, value) {
- this.key = key;
- this.value = value;
- this.prev = null;
- this.next = null;
- };
-
- var EntryList = function () {
- this.first = null;
- this.last = null;
- };
- EntryList.prototype =
- {
- addLast: function (entry) {
- if (this.last != null) {
- this.last.next = entry;
- entry.prev = this.last;
- this.last = entry;
- } else this.first = this.last = entry;
- },
-
- replace: function (entry, newEntry) {
- if (entry.prev != null) {
- entry.prev.next = newEntry;
- newEntry.prev = entry.prev;
- } else this.first = newEntry;
-
- if (entry.next != null) {
- entry.next.prev = newEntry;
- newEntry.next = entry.next;
- } else this.last = newEntry;
-
- },
-
- remove: function (entry) {
- if (entry.prev != null) entry.prev.next = entry.next;
- else this.first = entry.next;
-
- if (entry.next != null) entry.next.prev = entry.prev;
- else this.last = entry.prev;
- }
- };
-
- // Overload:function()
- // Overload:function(compareSelector)
- var Dictionary = function (compareSelector) {
- this.countField = 0;
- this.entryList = new EntryList();
- this.buckets = {}; // as Dictionary<string,List<object>>
- this.compareSelector = (compareSelector == null) ? Functions.Identity : compareSelector;
- };
- Dictionary.prototype =
- {
- add: function (key, value) {
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- var entry = new HashEntry(key, value);
- if (callHasOwnProperty(this.buckets, hash)) {
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- this.entryList.replace(array[i], entry);
- array[i] = entry;
- return;
- }
- }
- array.push(entry);
- } else {
- this.buckets[hash] = [entry];
- }
- this.countField++;
- this.entryList.addLast(entry);
- },
-
- get: function (key) {
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return undefined;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- var entry = array[i];
- if (this.compareSelector(entry.key) === compareKey) return entry.value;
- }
- return undefined;
- },
-
- set: function (key, value) {
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (callHasOwnProperty(this.buckets, hash)) {
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- var newEntry = new HashEntry(key, value);
- this.entryList.replace(array[i], newEntry);
- array[i] = newEntry;
- return true;
- }
- }
- }
- return false;
- },
-
- contains: function (key) {
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return false;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) return true;
- }
- return false;
- },
-
- clear: function () {
- this.countField = 0;
- this.buckets = {};
- this.entryList = new EntryList();
- },
-
- remove: function (key) {
- var compareKey = this.compareSelector(key);
- var hash = computeHashCode(compareKey);
- if (!callHasOwnProperty(this.buckets, hash)) return;
-
- var array = this.buckets[hash];
- for (var i = 0; i < array.length; i++) {
- if (this.compareSelector(array[i].key) === compareKey) {
- this.entryList.remove(array[i]);
- array.splice(i, 1);
- if (array.length == 0) delete this.buckets[hash];
- this.countField--;
- return;
- }
- }
- },
-
- count: function () {
- return this.countField;
- },
-
- toEnumerable: function () {
- var self = this;
- return new Enumerable(function () {
- var currentEntry;
-
- return new IEnumerator(
- function () { currentEntry = self.entryList.first; },
- function () {
- if (currentEntry != null) {
- var result = { key: currentEntry.key, value: currentEntry.value };
- currentEntry = currentEntry.next;
- return this.yieldReturn(result);
- }
- return false;
- },
- Functions.Blank);
- });
- }
- };
-
- return Dictionary;
- })();
-
- // dictionary = Dictionary<TKey, TValue[]>
- var Lookup = function (dictionary) {
- this.count = function () {
- return dictionary.count();
- };
- this.get = function (key) {
- return Enumerable.from(dictionary.get(key));
- };
- this.contains = function (key) {
- return dictionary.contains(key);
- };
- this.toEnumerable = function () {
- return dictionary.toEnumerable().select(function (kvp) {
- return new Grouping(kvp.key, kvp.value);
- });
- };
- };
-
- var Grouping = function (groupKey, elements) {
- this.key = function () {
- return groupKey;
- };
- ArrayEnumerable.call(this, elements);
- };
- Grouping.prototype = new ArrayEnumerable();
-
- // module export
- if (typeof define === Types.Function && define.amd) { // AMD
- define("linqjs", [], function () { return Enumerable; });
- }
- else if (typeof module !== Types.Undefined && module.exports) { // Node
- module.exports = Enumerable;
- }
- else {
- root.Enumerable = Enumerable;
- }
-})(this);
\ No newline at end of file
diff --git a/data/libs/linqjs/reference.htm b/data/libs/linqjs/reference.htm
deleted file mode 100644
index 0e5b3e2aa..000000000
--- a/data/libs/linqjs/reference.htm
+++ /dev/null
@@ -1,3205 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>linq.js Reference</title>
- <script type="text/javascript" src="linq.js"></script>
- <script type="text/javascript">
- var textStack = [];
- document.write = function() {
- Enumerable.from(arguments).forEach("textStack.push($)");
- };
- document.writeln = function () {
- Enumerable.from(arguments).forEach("textStack.push($)");
- };
-
- function evaluate(code) {
- textStack.length = 0;
- var value;
- try {
- eval(code + '.take(1001).writeLine()');
- value = textStack.join("");
- } catch (e) {
- textStack.length = 0;
- try {
- value = eval("(" + code + ")");
- document.write(value);
- value = textStack.join("");
- }
- catch (e2) {
- value = "error";
- }
- }
- return value;
- }
-
- function expand() {
- var code = (this.innerText || this.textContent);
- var value = evaluate(code);
- var p = document.createElement("p");
- p.innerHTML = value;
- this.appendChild(p);
- this.onclick = collapse;
- }
-
- function collapse() {
- this.removeChild(this.lastChild);
- this.onclick = expand;
- }
-
- function execute() {
- var value = evaluate(this.value);
- document.getElementById("codeResult").innerHTML = value;
- }
-
- window.onload = function() {
- Enumerable.from(document.getElementsByTagName("pre"))
- .forEach("$.onclick = expand");
-
- var input = document.getElementById("codeInput");
- input.onkeyup = execute;
- execute.apply(input);
- };
- </script>
- <style type="text/css">
- pre
- {
- cursor: pointer;
- }
- table
- {
- width: 100%;
- border-collapse: collapse;
- }
- td
- {
- border: solid black;
- border-width: 1px 0 1px 0;
- }
- h2
- {
- width: 100%;
- }
- </style>
-</head>
-<body>
- <h1>
- linq.js Reference</h1>
- <p>
- Notice:currently under working for v3.0. lack of some methods(choose, merge, defer, etc...)<br />
- <a href="http://linqjs.codeplex.com/">http://linqjs.codeplex.com/</a>
- </p>
- <h2>
- LINQ Pad</h2>
- <table>
- <tr>
- <td style="width: 50%; vertical-align: top">
- <textarea cols="10" rows="10" id="codeInput" style="width: 100%">Enumerable.range(0, 20)&#13;.where("x => x % 3 == 0")&#13;.select("$ * 2")</textarea>
- </td>
- <td style="vertical-align: top">
- <p id="codeResult" style="padding-left: 20px">
- </p>
- </td>
- </tr>
- </table>
- <h2 class="clear:both">
- Generating Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="2">
- choice
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- params T[] elements
- </td>
- <td>
- <pre>Enumerable.choice("a","b","c","d").take(10)</pre>
- <pre>Enumerable.choice(["a","b","c","d"]).take(10)</pre>
- </td>
- </tr>
- <tr>
- <td>
- Enumerable elements
- </td>
- <td>
- <pre>Enumerable.choice(Enumerable.range(1,3)).take(10)</pre>
- </td>
- </tr>
- <tr>
- <td>
- cycle
- </td>
- <td>
- Enumerable
- </td>
- <td>
- params T obj
- </td>
- <td>
- <pre>Enumerable.cycle(1,"foo",true).take(10)</pre>
- <pre>Enumerable.cycle([1,"foo",true]).take(10)</pre>
- </td>
- </tr>
- <tr>
- <td>
- empty
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.empty()</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="6">
- from
- </td>
- <td rowspan="6">
- Enumerable
- </td>
- <td>
- Array obj
- </td>
- <td>
- <pre>var arr = [1,124,"aaa",function(){},false];
-Enumerable.from(arr)</pre>
- </td>
- </tr>
- <tr>
- <td>
- Object obj
- </td>
- <td>
- <pre>var obj = {a:3,b:"3",z:function(){},d:true};
-Enumerable.from(obj).select("$.key + ':' + $.value")</pre>
- </td>
- </tr>
- <tr>
- <td>
- NodeList obj
- </td>
- <td>
- <pre>var node = document.getElementsByTagName("h2");
-Enumerable.from(node).select("$.innerHTML")</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number obj
- </td>
- <td>
- <pre>Enumerable.from(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- String obj
- </td>
- <td>
- <pre>Enumerable.from("foobar")</pre>
- </td>
- </tr>
- <tr>
- <td>
- IEnumerable(WSH) obj
- </td>
- <td>
- <pre>
-// 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($)");</pre>
- </td>
- </tr>
- <tr>
- <td>
- make
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T element
- </td>
- <td>
- <pre>Enumerable.make("foobar")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- matches
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- string input, RegExp pattern
- </td>
- <td>
- <pre>Enumerable.matches("xbcyBCzbc", /(.)bc/i)
-.select("'index='+$.index+' all='+$[0]+' capture='+$[1]")</pre>
- </td>
- </tr>
- <tr>
- <td>
- string input, string pattern
- </td>
- <td>
- <pre>Enumerable.matches("xbcyBCzbc", "(.)bc")
-.select("'index='+$.index+' all='+$[0]+' capture='+$[1]")</pre>
- </td>
- </tr>
- <tr>
- <td>
- string input, string pattern, string flags
- </td>
- <td>
- <pre>Enumerable.matches("xbcyBCzbc", "(.)bc", "i")
-.select("'index='+$.index+' all='+$[0]+' capture='+$[1]")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- range
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- int start, int count
- </td>
- <td>
- <pre>Enumerable.range(10,5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start, int count, int step
- </td>
- <td>
- <pre>Enumerable.range(10,5,3)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- rangeDown
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- int start, int count
- </td>
- <td>
- <pre>Enumerable.rangeDown(10,5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start, int count, int step
- </td>
- <td>
- <pre>Enumerable.rangeDown(10,5,3)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- rangeTo
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- int start, int to
- </td>
- <td>
- <pre>Enumerable.rangeTo(10,18)</pre>
- <pre>Enumerable.rangeTo(3,-5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start, int to, int step
- </td>
- <td>
- <pre>Enumerable.rangeTo(1,9,3)</pre>
- <pre>Enumerable.rangeTo(1,-9,3)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- repeat
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T obj
- </td>
- <td>
- <pre>Enumerable.repeat(3).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T obj, int count
- </td>
- <td>
- <pre>Enumerable.repeat("foo",10)</pre>
- </td>
- </tr>
- <tr>
- <td>
- repeatWithFinalize
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T initializer(), void finalizer(T)
- </td>
- <td>
- <pre>// 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() });
-</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- generate
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T func()
- </td>
- <td>
- <pre>Enumerable.generate("Math.random()").take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T func(), int count
- </td>
- <td>
- <pre>Enumerable.generate("Math.random()", 5)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- toInfinity
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.toInfinity().take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start
- </td>
- <td>
- <pre>Enumerable.toInfinity(1000).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start, int step
- </td>
- <td>
- <pre>Enumerable.toInfinity(1000,5).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- toNegativeInfinity
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.toNegativeInfinity().take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start
- </td>
- <td>
- <pre>Enumerable.toNegativeInfinity(1000).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- int start, int step
- </td>
- <td>
- <pre>Enumerable.toNegativeInfinity(1000,5).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- unfold
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T seed, T func(T)
- </td>
- <td>
- <pre>Enumerable.unfold(5, "$+3").take(10)</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Projection and Filtering Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="3">
- traverseBreadthFirst
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- T[] func(T)
- </td>
- <td>
- <pre>Enumerable.make(1).traverseBreadthFirst("$+$").take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] func(T), T resultSelector(T)
- </td>
- <td>
- <pre>Enumerable.make(1).traverseBreadthFirst("$+$","$*$").take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] func(T), T resultSelector(T, int)
- </td>
- <td>
- <pre>Enumerable.make(document.body)
-.traverseBreadthFirst("$.childNodes", "v,n=>{value:v,nestLevel:n}")
-.where("$.nestLevel<3 && $.value.nodeType == 1")
-.select("$.nestLevel + ':' + $.value.tagName")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- traverseDepthFirst
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- T[] func(T)
- </td>
- <td>
- <pre>Enumerable.make(1).traverseDepthFirst("$+$").take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] func(T), T resultSelector(T)
- </td>
- <td>
- <pre>Enumerable.make(1).traverseDepthFirst("$+$","$*$").take(5)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] func(T), T resultSelector(T, int)
- </td>
- <td>
- <pre>Enumerable.make(document.body)
-.traverseDepthFirst("$.childNodes", "v,n=>{value:v,nestLevel:n}")
-.where("$.nestLevel<3 && $.value.nodeType == 1")
-.select("$.nestLevel + ':' + $.value.tagName")</pre>
- </td>
- </tr>
- <tr>
- <td>
- flatten
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>var array = [1,[234,2,[62,3]],[234,5],3];
-Enumerable.from(array).flatten()</pre>
- </td>
- </tr>
- <tr>
- <td>
- pairwise
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T selector(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,10)
-.pairwise("prev,next=>prev + ':' + next")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- scan
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- T func(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).scan("a,b=>a+b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T seed, T func(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).scan(100,"a,b=>a+b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T seed, T func(T, T), T resultSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).scan(100,"a,b=>a+b","$*10")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- select
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T selector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).select("$*10")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T selector(T, int)
- </td>
- <td>
- <pre>Enumerable.rangeDown(10,10).select("value,index=>index + ':' + value")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="4">
- selectMany
- </td>
- <td rowspan="4">
- Enumerable
- </td>
- <td>
- T[] collectionSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,3).selectMany("Enumerable.repeat($,3)")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] collectionSelector(T, int)
- </td>
- <td>
- <pre>Enumerable.range(5,5)
-.selectMany("value,index=>Enumerable.repeat('str'+value,index+1)")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] collectionSelector(T), resultSelector(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,3)
-.selectMany("Enumerable.repeat($,3)","first,middle=>first + ':' + middle*10")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] collectionSelector(T, int), resultSelector(T, T)
- </td>
- <td>
- <pre>Enumerable.range(5,5)
-.selectMany("v,i=>Enumerable.repeat('str'+v,i+1)","f,m=>f + ':' + m")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- where
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).where("$%2==0")</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T, int)
- </td>
- <td>
- <pre>Enumerable.range(1,10).where("value,index=>value*index>10")</pre>
- </td>
- </tr>
- <tr>
- <td>
- ofType
- </td>
- <td>
- Enumerable
- </td>
- <td>
- Class type
- </td>
- <td>
- <pre>Enumerable.from([1,"a",2,"b","c",3]).ofType(Number)</pre>
- <pre>Enumerable.from([1,"a",2,"b","c",3]).ofType(String)</pre>
- <pre>function ClassA(v){this.v = v}
-Enumerable.from([new ClassA("a"),1,2,new ClassA("b")])
- .ofType(ClassA).select("$.v")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- zip
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] second,T selector(T, T)
- </td>
- <td>
- <pre>Enumerable.rangeDown(10,10)
-.zip(Enumerable.range(1,10),"outer,inner=>outer + ':' + inner")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] second,T selector(T, T, int)
- </td>
- <td>
- <pre>Enumerable.rangeDown(10,10)
-.zip(Enumerable.range(1,10),"outer,inner,index=>index + ':' + outer*inner")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Join Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="2">
- join
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, T)
- </td>
- <td>
- <pre>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")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, T),
- T compareSelector(T)
- </td>
- <td>
- <pre>var array1 = [10,405,50,135];
-var array2 = [1,4,7,8];
-Enumerable.from(array1)
-.join(array2,"","","outer,inner=>outer + ':' + inner","$%2==0")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- groupJoin
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, Enumerable)
- </td>
- <td>
- <pre>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.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] inner, T outerKeySelector(T), T innerKeySelector(T), T resultSelector(T, Enumerable),
- T compareSelector(T)
- </td>
- <td>
- <pre>var array1 = [10,405,50,135];
-var array2 = [1,4,7,8];
-Enumerable.from(array1)
-.groupJoin(array2,"","","outer,lookup=>outer + ':' + lookup.toJoinedString('-')","$%2==0")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Set Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- all
- </td>
- <td>
- Boolean
- </td>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).all("$<5")</pre>
- <pre>Enumerable.range(1,10).all("$<15")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- any
- </td>
- <td rowspan="2">
- Boolean
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,0).any()</pre>
- <pre>Enumerable.range(1,10).any()</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).any("$==5")</pre>
- <pre>Enumerable.range(1,10).any("$==15")</pre>
- </td>
- </tr>
- <tr>
- <td>
- concat
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T[] second
- </td>
- <td>
- <pre>Enumerable.range(1,5).concat(Enumerable.repeat("foo",5))</pre>
- </td>
- </tr>
- <tr>
- <td>
- insert
- </td>
- <td>
- Enumerable
- </td>
- <td>
- int index, T[] second
- </td>
- <td>
- <pre>Enumerable.range(1,5).insert(3,Enumerable.repeat("foo",5))</pre>
- </td>
- </tr>
- <tr>
- <td>
- alternate
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T value
- </td>
- <td>
- <pre>Enumerable.range(1,5).alternate(-1)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- contains
- </td>
- <td rowspan="2">
- Boolean
- </td>
- <td>
- T value
- </td>
- <td>
- <pre>Enumerable.range(1,5).contains(3)</pre>
- <pre>Enumerable.range(1,5).contains(10)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T value, T compareSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,5).Select("{test:$}").contains(3)</pre>
- <pre>Enumerable.range(1,5).Select("{test:$}").contains(3,"$.test")</pre>
- </td>
- </tr>
- <tr>
- <td>
- defaultIfEmpty
- </td>
- <td>
- Enumerable
- </td>
- <td>
- T defaultValue
- </td>
- <td>
- <pre>Enumerable.range(1,5).defaultIfEmpty("default")</pre>
- <pre>Enumerable.range(1,0).defaultIfEmpty("default")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- distinct
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>var array = [1,412,5,3,5,412,7];
-Enumerable.from(array).distinct()</pre>
- </td>
- </tr>
- <tr>
- <td>
- T compareSelector(T)
- </td>
- <td>
- <pre>var seq = Enumerable.range(1,10).Select("{test:$%3}");
-seq.distinct("$.test").select("$.test")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- except
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] second
- </td>
- <td>
- <pre>var array1 = [1,412,5,3,5,412,7];
-var array2 = [20,12,5,5,7,310];
-Enumerable.from(array1).except(array2)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] second, T compareSelector(T)
- </td>
- <td>
- <pre>var seq1 = Enumerable.range(1,10).select("{test:$%5}");
-var seq2 = Enumerable.range(1,10).select("{test:$%2}");
-seq1.except(seq2,"$.test").select("$.test")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- intersect
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] second
- </td>
- <td>
- <pre>var array1 = [1,412,5,3,5,412,7];
-var array2 = [20,12,5,5,7,310];
-Enumerable.from(array1).intersect(array2)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] second, T compareSelector(T)
- </td>
- <td>
- <pre>var seq1 = Enumerable.range(1,10).select("{test:$%5}");
-var seq2 = Enumerable.range(1,10).select("{test:$%2}");
-seq1.intersect(seq2,"$.test").select("$.test")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- sequenceEqual
- </td>
- <td rowspan="2">
- Boolean
- </td>
- <td>
- T[] second
- </td>
- <td>
- <pre>Enumerable.range(1,5).sequenceEqual(Enumerable.range(1,5))</pre>
- <pre>Enumerable.range(1,5).sequenceEqual(Enumerable.range(1,6))</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] second, T compareSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).select("{test:$%5}")
-.sequenceEqual(Enumerable.range(1,10).select("{test:$%5}"),"$.test")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- union
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T[] second
- </td>
- <td>
- <pre>var array1 = [1,412,5,3,5,412,7];
-var array2 = [20,12,5,5,7,310];
-Enumerable.from(array1).union(array2)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T[] second, T compareSelector(T)
- </td>
- <td>
- <pre>var seq1 = Enumerable.range(1,5).select("{test:$}");
-var seq2 = Enumerable.range(3,7).select("{test:$}");
-seq1.union(seq2,"$.test").select("$.test")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Ordering Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="2">
- orderBy
- </td>
- <td rowspan="2">
- OrderedEnumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>
-var array = [1,51,61,75,8,35,43];
-Enumerable.from(array).orderBy()</pre>
- </td>
- </tr>
- <tr>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>
-var array = [{a:"a"},{a:"z"},{a:"k"},{a:"l"},{a:"m"},{a:"c"}];
-Enumerable.from(array).orderBy("$.a").select("$.a")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- orderByDescending
- </td>
- <td rowspan="2">
- OrderedEnumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>
-var array = [1,51,61,75,8,35,43];
-Enumerable.from(array).orderByDescending()</pre>
- </td>
- </tr>
- <tr>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>
-var array = [{a:"a"},{a:"z"},{a:"k"},{a:"l"},{a:"m"},{a:"c"}];
-Enumerable.from(array).orderByDescending("$.a").select("$.a")</pre>
- </td>
- </tr>
- <tr>
- <td>
- thenBy
- </td>
- <td>
- OrderedEnumerable
- </td>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>
-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")</pre>
- </td>
- </tr>
- <tr>
- <td>
- thenByDescending
- </td>
- <td>
- OrderedEnumerable
- </td>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>
-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")</pre>
- </td>
- </tr>
- <tr>
- <td>
- reverse
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).reverse()</pre>
- </td>
- </tr>
- <tr>
- <td>
- shuffle
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).shuffle()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Grouping Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="4">
- groupBy
- </td>
- <td rowspan="2">
- Enumerable&lt;Grouping>
- </td>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,5).groupBy("$%2==0")
-.select("$.key() + ':' + $.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T keySelector(T), T elementSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,5).groupBy("$%2==0","$*10")
-.select("$.key() + ':' + $.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T keySelector(T), T elementSelector(T), T resultSelector(T, Enumerable)
- </td>
- <td>
- <pre>Enumerable.range(1,5)
-.groupBy("$%2==0","","key,e=>key+':'+e.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td>
- TK keySelector(T), TE elementSelector(T), TR resultSelector(T, Enumerable),TC compareSelector(TK)
- </td>
- <td>
- <pre>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()")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="4">
- partitionBy
- </td>
- <td rowspan="2">
- Enumerable&lt;Grouping>
- </td>
- <td>
- T keySelector(T)
- </td>
- <td>
- <pre>Enumerable.from([1,2,2,3,3,2,1,1]).partitionBy("i=>i")
-.select("$.key() + ':' + $.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T keySelector(T), T elementSelector(T)
- </td>
- <td>
- <pre>Enumerable.from([1,2,2,3,3,2,1,1]).partitionBy("i=>i","i=>i*100")
-.select("$.key() + ':' + $.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- T keySelector(T), T elementSelector(T), T resultSelector(T, Enumerable)
- </td>
- <td>
- <pre>Enumerable.from([1,2,2,3,3,2,1,1])
-.partitionBy("i=>i","i=>i","key,e=>key+':'+e.toJoinedString('-')")</pre>
- </td>
- </tr>
- <tr>
- <td>
- TK keySelector(T), TE elementSelector(T), TR resultSelector(T, Enumerable), TC compareSelector(TK)
- </td>
- <td>
- <pre>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()")</pre>
- </td>
- </tr>
- <tr>
- <td>
- buffer
- </td>
- <td>
- Enumerable&lt;Array>
- </td>
- <td>
- int count
- </td>
- <td>
- <pre>Enumerable.range(1,10).buffer(4)</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Aggregate Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="3">
- aggregate
- </td>
- <td rowspan="3">
- T
- </td>
- <td>
- T func(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,5).aggregate("a,b=>a*b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T seed, T func(T, T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).aggregate(100,"a,b=>a+b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- T seed, T func(T, T), T resultSelector(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).aggregate(100,"a,b=>a+b","$*10")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- average
- </td>
- <td rowspan="2">
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).average()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.average("$.b")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- count
- </td>
- <td rowspan="2">
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).count()</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).count("$>7")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- max
- </td>
- <td rowspan="2">
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).max()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.max("$.b")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- min
- </td>
- <td rowspan="2">
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).min()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.min("$.b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- maxBy
- </td>
- <td>
- T
- </td>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.maxBy("$.b").a</pre>
- </td>
- </tr>
- <tr>
- <td>
- minBy
- </td>
- <td>
- T
- </td>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.minBy("$.b").a</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- sum
- </td>
- <td rowspan="2">
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).sum()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:5},{a:"bar",b:20},{a:"foobar",b:10}])
-.sum("$.b")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Paging Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- elementAt
- </td>
- <td>
- T
- </td>
- <td>
- int index
- </td>
- <td>
- <pre>Enumerable.range(1,10).elementAt(3)</pre>
- </td>
- </tr>
- <tr>
- <td>
- elementAtOrDefault
- </td>
- <td>
- T
- </td>
- <td>
- int index, T defaultValue
- </td>
- <td>
- <pre>Enumerable.range(1,10).elementAtOrDefault(15,-1)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- first
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).first()</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).first("$>4")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- firstOrDefault
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- T defaultValue
- </td>
- <td>
- <pre>Enumerable.empty().firstOrDefault(-1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T defaultValue, bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).firstOrDefault(-1,"$>15")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- last
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).last()</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).last("$<4")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- lastOrDefault
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- T defaultValue
- </td>
- <td>
- <pre>Enumerable.empty().lastOrDefault(-1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T defaultValue, bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).lastOrDefault(-1,"$>15")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- single
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.from("a").single()</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).single("$==4")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- singleOrDefault
- </td>
- <td rowspan="2">
- T
- </td>
- <td>
- T defaultValue
- </td>
- <td>
- <pre>Enumerable.empty().singleOrDefault(-1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- T defaultValue, bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).singleOrDefault(-1,"$==15")</pre>
- </td>
- </tr>
- <tr>
- <td>
- skip
- </td>
- <td>
- Enumerable
- </td>
- <td>
- int count
- </td>
- <td>
- <pre>Enumerable.range(1,10).skip(5)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- skipWhile
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).skipWhile("$<=5")</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T, int index)
- </td>
- <td>
- <pre>Enumerable.range(1,10).skipWhile("value,index=>value+index<=5")</pre>
- </td>
- </tr>
- <tr>
- <td>
- take
- </td>
- <td>
- Enumerable
- </td>
- <td>
- int count
- </td>
- <td>
- <pre>Enumerable.range(1,10).take(5)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- takeWhile
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- bool predicate(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).takeWhile("$<=5")</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool predicate(T, int index)
- </td>
- <td>
- <pre>Enumerable.range(1,10).takeWhile("value,index=>value+index<=5")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- takeExceptLast
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).takeExceptLast()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Number count
- </td>
- <td>
- <pre>Enumerable.range(1,10).takeExceptLast(3)</pre>
- </td>
- </tr>
- <tr>
- <td>
- takeFromLast
- </td>
- <td>
- Enumerable
- </td>
- <td>
- Number count
- </td>
- <td>
- <pre>Enumerable.range(1,10).takeFromLast(3)</pre>
- </td>
- </tr>
- <tr>
- <td>
- indexOf
- </td>
- <td>
- int
- </td>
- <td>
- T item
- </td>
- <td>
- <pre>Enumerable.range(1,10).indexOf(3)</pre>
- <pre>Enumerable.range(1,10).indexOf(15)</pre>
- </td>
- </tr>
- <tr>
- <td>
- lastIndexOf
- </td>
- <td>
- int
- </td>
- <td>
- T item
- </td>
- <td>
- <pre>Enumerable.from([1,2,3,2,5]).lastIndexOf(2)</pre>
- <pre>Enumerable.from([1,2,3,2,5]).lastIndexOf(20)</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Convert Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- toArray
- </td>
- <td>
- Array
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).toArray()</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- toLookup
- </td>
- <td rowspan="3">
- Lookup
- </td>
- <td>
- TKey keySelector(T)
- </td>
- <td>
- <pre>var lookup = Enumerable.from(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
-.toLookup("$.match(/\\.(.+$)/)[1]");
-lookup.toEnumerable().select("$.key() + ' : ' + $.toArray()")</pre>
- </td>
- </tr>
- <tr>
- <td>
- TKey keySelector(T), TElement elementSelector(T)
- </td>
- <td>
- <pre>var lookup = Enumerable.from(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
-.toLookup("$.match(/\\.(.+$)/)[1]","$.match(/(.+)\\.[^.]+$/)[1]");
-lookup.toEnumerable().select("$.key() + ' : ' + $.toArray()")</pre>
- </td>
- </tr>
- <tr>
- <td>
- TKey keySelector(T), TElement elementSelector(T), TCompare compareSelector(TKey)
- </td>
- <td>
- <pre>var lookup = Enumerable.from(["temp.xls", "temp.pdf", "temp.jpg", "temp2.pdf"])
-.toLookup("","","$.match(/\\.(.+$)/)[1]");
-lookup.toEnumerable().select("$.key() + ' : ' + $.toArray()")</pre>
- </td>
- </tr>
- <tr>
- <td>
- toObject
- </td>
- <td>
- Object
- </td>
- <td>
- String keySelector(T), T elementSelector(T)
- </td>
- <td>
- <pre>var obj = Enumerable.range(1,10).select("value,index=>{id:'id_' + index,value:value}")
-.toObject("$.id","$.value");
-Enumerable.from(obj).select("$.key + ':' + $.value")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- toDictionary
- </td>
- <td rowspan="2">
- Dictionary
- </td>
- <td>
- TKey keySelector(T), TElement elementSelector(T)
- </td>
- <td>
- <pre>var dict = Enumerable.range(1,10).select("value,index=>{id:'id_' + index,value:value}")
-.toDictionary("$.id","$.value");
-dict.toEnumerable().select("$.key + ':' + $.value")</pre>
- </td>
- </tr>
- <tr>
- <td>
- TKey keySelector(T), TElement elementSelector(T), TCompare compareSelector(TKey)
- </td>
- <td>
- <pre>var dict = Enumerable.range(1,10).select("value,index=>{id:'id_' + index,value:value}")
-.toDictionary("$","$.value","$;id");
-dict.toEnumerable().select("$.key.id + ':' + $.value")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- toJSONString
- </td>
- <td rowspan="3">
- String
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// toJSONString only work Native JSON support browser or include json2.js
-Enumerable.from([{Foo:1, Bar:'z'},{Foo:5, Bar:null}]).toJSONString()</pre>
- </td>
- </tr>
- <tr>
- <td>
- TResult replacer(TKey, TValue)
- </td>
- <td>
- <pre>Enumerable.from(["a","b","c"])
-.toJSONString(function(k,v){return (typeof v === 'object') ? v : v.toString().toUpperCase()})</pre>
- </td>
- </tr>
- <tr>
- <td>
- TResult replacer(TKey, TValue), Number space
- </td>
- <td>
- <pre>Enumerable.range(1, 5).toJSONString(null, 4)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- toJoinedString
- </td>
- <td rowspan="3">
- String
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(0,10).toJoinedString()</pre>
- </td>
- </tr>
- <tr>
- <td>
- String separator
- </td>
- <td>
- <pre>Enumerable.range(0,10).toJoinedString("-")</pre>
- </td>
- </tr>
- <tr>
- <td>
- String separator, T selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{k:"foo"},{k:"bar"}]).toJoinedString("-","$.k")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Action Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="2">
- doAction
- </td>
- <td rowspan="2">
- Enumerable
- </td>
- <td>
- void action(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).doAction(function(i){
- document.write('do:'+ i +'|');})
- .where("$%2==0")</pre>
- </td>
- </tr>
- <tr>
- <td>
- void action(T, index)
- </td>
- <td>
- <pre>Enumerable.range(1,10).doAction(function(value,index){
- document.write("do:" + index + '-' + value + "&lt;br/>");})
-.orderBy("").take(2)</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="4">
- forEach
- </td>
- <td rowspan="4">
- void
- </td>
- <td>
- void action(T)
- </td>
- <td>
- <pre>Enumerable.range(1,10).forEach(function(i){
- document.write(i);})</pre>
- </td>
- </tr>
- <tr>
- <td>
- void action(T, index)
- </td>
- <td>
- <pre>Enumerable.range(1,10).forEach(function(value,index){
- document.write(index + ':' + value + "&lt;br/>");})</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool func(T)
- </td>
- <td>
- <pre>Enumerable.range(1, 10).forEach(function(i)
-{
- if (i % 2 == 0) return; // continue
- if (i > 6) return false; // break
- document.write(i + "&lt;br/>");
-})</pre>
- </td>
- </tr>
- <tr>
- <td>
- bool func(T, index)
- </td>
- <td>
- <pre>Enumerable.repeat("aaa", 10).forEach(function(s,index)
-{
- if (index % 2 == 0) return; // continue
- if (index > 6) return false; // break
- document.write(index + s + "&lt;br/>");
-})</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- write
- </td>
- <td rowspan="3">
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).write()</pre>
- </td>
- </tr>
- <tr>
- <td>
- String separator
- </td>
- <td>
- <pre>Enumerable.range(1,10).write("-")</pre>
- </td>
- </tr>
- <tr>
- <td>
- String separator, T selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:1},{a:"bar",b:3}])
-.write("-","$.a + ':' + $.b")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="2">
- writeLine
- </td>
- <td rowspan="2">
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).writeLine()</pre>
- </td>
- </tr>
- <tr>
- <td>
- T selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:1},{a:"bar",b:3}])
-.writeLine("$.a + ':' + $.b")</pre>
- </td>
- </tr>
- <tr>
- <td>
- force
- </td>
- <td>
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).trace().force()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Functional Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- letBind
- </td>
- <td>
- Enumerable
- </td>
- <td>
- Enumerable&lt;TR> func(Enumerable&lt;T>)
- </td>
- <td>
- <pre>Enumerable.range(1,10).letBind(function(x){return x.zip(x.skip(1),"x,y=>x + ':' + y")})</pre>
- </td>
- </tr>
- <tr>
- <td>
- share
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>var share = Enumerable.range(1,10).share();
-share.take(4).writeLine();
-document.write("--- &lt;br>");
-share.skip(2)</pre>
- </td>
- </tr>
- <tr>
- <td>
- memoize
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>var mem = Enumerable.range(1,10)
-.doAction("document.write('--->' + $ + '&lt;br>')").memoize();
-mem.where("$%2==0").writeLine();
-document.write("--- &lt;br>");
-mem.where("$%2==0")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Error Handling Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- catchError
- </td>
- <td>
- Enumerable
- </td>
- <td>
- void handler(Error)
- </td>
- <td>
- <pre>Enumerable.range(1,10).select(function(i){
- if(i == 5) throw new Error("enumerable_error"); else return i;})
-.catchError("document.write($.message)")</pre>
- </td>
- </tr>
- <tr>
- <td>
- finallyAction
- </td>
- <td>
- Enumerable
- </td>
- <td>
- void finallyAction()
- </td>
- <td>
- <pre>Enumerable.range(1,5).finallyAction(function(){document.write("finally")})</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- For Debug Methods</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="3">
- trace
- </td>
- <td rowspan="3">
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// trace is output to console.log
-Enumerable.range(1,10).trace().force()</pre>
- </td>
- </tr>
- <tr>
- <td>
- String message
- </td>
- <td>
- <pre>Enumerable.range(1,10).trace("Gen").where("$%3==0").trace("Filtered").force()</pre>
- </td>
- </tr>
- <tr>
- <td>
- String message, T selector(T)
- </td>
- <td>
- <pre>Enumerable.from([{a:"foo",b:1},{a:"bar",b:3}])
-.trace("Gen","$.a").force()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- DisposableEnumerable(inherit Eunmerable)</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- dispose
- </td>
- <td>
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).share().dispose()</pre>
- </td>
- </tr>
- <tr>
- <td>
- All Enumerable Methods
- </td>
- <td>
- -
- </td>
- <td>
- -
- </td>
- <td>
- <pre>-</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Grouping(inherit Eunmerable)</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- <tr>
- <td>
- key
- </td>
- <td>
- TKey
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.from([{id:"foo",x:10},{id:"bar",x:20},{id:"foo",x:100}])
-.groupBy("$.id").toArray()[0] // grouping
-.key()</pre>
- </td>
- </tr>
- <tr>
- <td>
- All Enumerable Methods
- </td>
- <td>
- -
- </td>
- <td>
- -
- </td>
- <td>
- <pre>-</pre>
- </td>
- </tr>
- </thead>
- </table>
- <h2>
- Utils</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="3">
- createLambda
- </td>
- <td rowspan="3">
- Function
- </td>
- <td>
- null/undefined
- </td>
- <td>
- <pre>Enumerable.Utils.createLambda()</pre>
- </td>
- </tr>
- <tr>
- <td>
- Function expression
- </td>
- <td>
- <pre>Enumerable.Utils.createLambda(function(x){ return x % 2 == 0})</pre>
- </td>
- </tr>
- <tr>
- <td>
- string expression
- </td>
- <td>
- <pre>Enumerable.Utils.createLambda("")</pre>
- <pre>Enumerable.Utils.createLambda("x, y => x + y")</pre>
- <pre>Enumerable.Utils.createLambda("$ * $$ * $$$")</pre>
- </td>
- </tr>
- <tr>
- <td>
- createEnumerable
- </td>
- <td>
- Enumerable
- </td>
- <td>
- Func&lt;IEnumerator> getEnumerator
- </td>
- <td>
- <pre>Enumerable.Utils.createEnumerable(function(){ return Enumerable.Utils.createEnumerator(); })</pre>
- </td>
- </tr>
- <tr>
- <td>
- createEnumerator
- </td>
- <td>
- Enumerable
- </td>
- <td>
- Action initialize, Action tryGetNext, Action dispose
- </td>
- <td>
- <pre>var enumerator;
-Enumerable.Utils.createEnumerator(
- function(){ enumerator = Enumerable.range(1,10).getEnumerator(); },
- // tryGetNext's "this" is yielder, it have yieldReturn and yieldBreak
- function(){ return (enumerator.moveNext())
- ? this.yieldReturn(enumerator.current())
- : this.yieldBreak();},
- function(){ enumerator.dispose(); })</pre>
- </td>
- </tr>
- <tr>
- <td>
- extendTo
- </td>
- <td>
- void
- </td>
- <td>
- Constructor type
- </td>
- <td>
- <pre>Enumerable.Utils.extendTo(Array)</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- IEnumerator</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- getEnumerator
- </td>
- <td>
- IEnumerator
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).getEnumerator()</pre>
- </td>
- </tr>
- <tr>
- <td>
- moveNext
- </td>
- <td>
- Boolean
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).getEnumerator().moveNext()</pre>
- </td>
- </tr>
- <tr>
- <td>
- current
- </td>
- <td>
- T
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).getEnumerator().current()</pre>
- </td>
- </tr>
- <tr>
- <td>
- dispose
- </td>
- <td>
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,10).getEnumerator().dispose()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Dictionary</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- add
- </td>
- <td>
- void
- </td>
- <td>
- TKey key, TValue value
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().add(1, 'aaa')</pre>
- </td>
- </tr>
- <tr>
- <td>
- get
- </td>
- <td>
- TValue
- </td>
- <td>
- TKey key
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().get(1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- set
- </td>
- <td>
- Boolean
- </td>
- <td>
- TKey key, TValue value
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().set(1, 'zzz')</pre>
- </td>
- </tr>
- <tr>
- <td>
- contains
- </td>
- <td>
- Boolean
- </td>
- <td>
- TKey key
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().contains(1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- clear
- </td>
- <td>
- void
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().clear()</pre>
- </td>
- </tr>
- <tr>
- <td>
- remove
- </td>
- <td>
- void
- </td>
- <td>
- TKey key
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().remove(1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- count
- </td>
- <td>
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.empty().toDictionary().count()</pre>
- </td>
- </tr>
- <tr>
- <td>
- toEnumerable
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>var dict = Enumerable.empty().toDictionary();
-dict.add("foo", 10); dict.add("bar", 200);
-dict.toEnumerable().select("$.key + ':' + $.value")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- Lookup</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- get
- </td>
- <td>
- Enumerable&lt;TElement>
- </td>
- <td>
- TKey key
- </td>
- <td>
- <pre>Enumerable.from([{x:1,s:'a'},{x:1,s:'z'}])
-.toLookup("$.x").get(1).select("$.x + ':' + $.s")</pre>
- </td>
- </tr>
- <tr>
- <td>
- contains
- </td>
- <td>
- Boolean
- </td>
- <td>
- TKey key
- </td>
- <td>
- <pre>Enumerable.from([{x:1,s:'a'},{x:1,s:'z'}])
-.toLookup("$.x").contains(1)</pre>
- </td>
- </tr>
- <tr>
- <td>
- count
- </td>
- <td>
- Number
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.range(1,5).toLookup().count()</pre>
- </td>
- </tr>
- <tr>
- <td>
- toEnumerable
- </td>
- <td>
- Enumerable&lt;Grouping>
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>Enumerable.from([{a:1,s:'foo'},{a:1,s:'bar'},{a:2,s:'zzzzz'}])
-.toLookup("$.a").toEnumerable()
-.select("$.key() + ':' + $.select('$.s').toJoinedString('-')")</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- jQuery Extension(linq.jquery.js)</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- tojQuery
- </td>
- <td>
- jQuery
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// Enumerable.repeat("foo",10).tojQuery()</pre>
- </td>
- </tr>
- <tr>
- <td>
- tojQueryAsArray
- </td>
- <td>
- jQuery
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// Enumerable.repeat("foo",10).tojQueryAsArray()</pre>
- </td>
- </tr>
- <tr>
- <td>
- toEnumerable
- </td>
- <td>
- Enumerable&lt;jQuery>
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// $("div").toEnumerable()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- RxJS Extension(linq.rx.js)</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- toObservable
- </td>
- <td>
- Rx.Observable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// Enumerable.range(1,10).toObservable()</pre>
- </td>
- </tr>
- <tr>
- <td>
- toEnumerable
- </td>
- <td>
- Enumerable
- </td>
- <td>
- ()
- </td>
- <td>
- <pre>// Rx.Observable.range(1,10).toEnumerable()</pre>
- </td>
- </tr>
- </tbody>
- </table>
- <h2>
- QUnit Extension(linq.qunit.js)</h2>
- <table>
- <thead>
- <tr>
- <td>
- method name
- </td>
- <td>
- return type
- </td>
- <td>
- arguments
- </td>
- <td>
- example (click code)
- </td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td rowspan="3">
- is
- </td>
- <td rowspan="3">
- void
- </td>
- <td>
- Object expected, [string message]
- </td>
- <td>
- <pre>// Math.pow(10, 2).is(100, "all objects are extended")</pre>
- </td>
- </tr>
- <tr>
- <td>
- params Object[] expected
- </td>
- <td>
- <pre>// Enumerable.range(1,3).is(1,2,3) // collection deepEqual</pre>
- </td>
- </tr>
- <tr>
- <td>
- Func&lt;T,bool> checker, [string message]
- </td>
- <td>
- <pre>// ({ a: "foo", b: "bar" }).is(function (x) { return x.a == "foo" && x.b == "bar" }, "checker must be function(can not use string lambda)")</pre>
- </td>
- </tr>
- <tr>
- <td rowspan="3">
- isNot
- </td>
- <td rowspan="3">
- void
- </td>
- <td>
- Object expected, [string message]
- </td>
- <td>
- <pre>// Math.pow(10, 2).isNot(-5, "all objects are extended")</pre>
- </td>
- </tr>
- <tr>
- <td>
- params Object[] expected
- </td>
- <td>
- <pre>// Enumerable.range(1,3).isNot(1,2,3,4) // collection deepEqual</pre>
- </td>
- </tr>
- <tr>
- <td>
- Func&lt;T,bool> checker, [string message]
- </td>
- <td>
- <pre>// ({ a: "foo", b: "bar" }).isNot(function (x) { return x.a == "hee" && x.b == "bee" }, "checker must be function(can not use string lambda)")</pre>
- </td>
- </tr>
- <tr>
- <td>
- isExpr
- </td>
- <td>
- void
- </td>
- <td>
- string expression, [string message]
- </td>
- <td>
- <pre>// ({ a: "foo", b: "bar" }).isExpr("$.a == 'foo' && $.b == 'bar'", "checker string is converted to lambda")</pre>
- </td>
- </tr>
- <tr>
- <td>
- isNotExpr
- </td>
- <td>
- void
- </td>
- <td>
- string expression, [string message]
- </td>
- <td>
- <pre>// ({ a: "foo", b: "bar" }).isNotExpr("$.a == 'bar' && $.b == 'foo'", "checker string is converted to lambda")</pre>
- </td>
- </tr>
- <tr>
- <td>
- isTrue
- </td>
- <td>
- void
- </td>
- <td>
- [string message]
- </td>
- <td>
- <pre>// (Enumerable.empty().firstOrDefault() === null).isTrue()</pre>
- </td>
- </tr>
- <tr>
- <td>
- isFalse
- </td>
- <td>
- void
- </td>
- <td>
- [string message]
- </td>
- <td>
- <pre>// Enumerable.range(1, 10).all("$<5").isFalse()</pre>
- </td>
- </tr>
- <tr>
- <td>
- expectError
- </td>
- <td>
- Error
- </td>
- <td>
- Action testCode, [string message]
- </td>
- <td>
- <pre>// Enumerable.Assert.expectError(function () { throw new Error("ERROOOOOR"); })</pre>
- </td>
- </tr>
- <tr>
- <td>
- doesNotThrow
- </td>
- <td>
- void
- </td>
- <td>
- Action testCode, [string message]
- </td>
- <td>
- <pre>// Enumerable.Assert.doesNotThrow(function () { })</pre>
- </td>
- </tr>
- </tbody>
- </table>
-</body>
-</html>
diff --git a/node-webkit/icon128.png b/node-webkit/icon128.png
deleted file mode 100644
index 900d7924a..000000000
Binary files a/node-webkit/icon128.png and /dev/null differ
diff --git a/node-webkit/package.json b/node-webkit/package.json
index fc9b86083..6c23d0882 100644
--- a/node-webkit/package.json
+++ b/node-webkit/package.json
@@ -4,7 +4,7 @@
"version": "1.4",
"main": "../data/index.html",
"window": {
- "icon": "icon128.png",
+ "icon": "../data/icons/icon128.png",
"toolbar": true,
"width": 1024,
"height": 800
diff --git a/node-webkit/package.tmpl.json b/node-webkit/package.tmpl.json
new file mode 100644
index 000000000..e2bb88f32
--- /dev/null
+++ b/node-webkit/package.tmpl.json
@@ -0,0 +1,14 @@
+{
+ "name": "@APPNAME@",
+ "description": "An open and extensible platform, providing web based user interface for your local files.",
+ "version": "@VERSION@.@BUILD@",
+ "main": "index.html",
+ "window": {
+ "icon": "icons/icon128.png",
+ "toolbar": false,
+ "width": 1024,
+ "height": 768
+ },
+ "nodejs": true,
+ "chromium-args" : "--data-path='./data/'"
+}
diff --git a/package.json b/package.json
index 6dc0db87a..35f592d15 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "tagspaces",
"license": "AGPL 3.0",
"author": "Ugg Rock",
- "version": "1.6.1474",
+ "version": "1.6.1494",
"fullName": "TagSpaces",
"id": "jid1-FBaMKxTifTSahQ",
"description": "TagSpaces is a firefox addon, which allows you to browse your local file system and add tags to your files.",
diff --git a/update.rdf b/update.rdf
index 0a484b3e2..6cdbff794 100644
--- a/update.rdf
+++ b/update.rdf
@@ -7,13 +7,13 @@
<r:Seq>
<r:li>
<r:Description>
- <version>1.6.1474</version>
+ <version>1.6.1494</version>
<targetApplication>
<r:Description>
<id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</id>
<minVersion>16.0</minVersion>
<maxVersion>*</maxVersion>
- <updateLink>http://tagspaces.com/releases/1.6/tagspaces.1.6.1474.xpi</updateLink>
+ <updateLink>http://tagspaces.com/releases/1.6/tagspaces.1.6.1494.xpi</updateLink>
<updateInfoURL>http://tagspaces.com/releases/1.6/updateInfo.xml</updateInfoURL>
</r:Description>
</targetApplication>