/*-------------------------------------------------------------------------- * linq-vsdoc.js - LINQ for JavaScript * ver 2.2.0.2 (Jan. 21th, 2011) * * created and maintained by neuecc * licensed under Microsoft Public License(Ms-PL) * http://neue.cc/ * http://linqjs.codeplex.com/ *--------------------------------------------------------------------------*/ Enumerable = (function () { var Enumerable = function (getEnumerator) { this.GetEnumerator = getEnumerator; } Enumerable.Choice = function (Params_Contents) { /// Random choice from arguments. /// Ex: Choice(1,2,3) - 1,3,2,3,3,2,1... /// Array or Params Contents /// } Enumerable.Cycle = function (Params_Contents) { /// Cycle Repeat from arguments. /// Ex: Cycle(1,2,3) - 1,2,3,1,2,3,1,2,3... /// Array or Params Contents /// } Enumerable.Empty = function () { /// Returns an empty Enumerable. /// } Enumerable.From = function (obj) { /// /// Make Enumerable from obj. /// 1. null = Enumerable.Empty(). /// 2. Enumerable = Enumerable. /// 3. Number/Boolean = Enumerable.Repeat(obj, 1). /// 4. String = to CharArray.(Ex:"abc" => "a","b","c"). /// 5. Object/Function = to KeyValuePair(except function) Ex:"{a:0}" => (.Key=a, .Value=0). /// 6. Array or ArrayLikeObject(has length) = to Enumerable. /// 7. JScript's IEnumerable = to Enumerable(using Enumerator). /// /// object /// } Enumerable.Return = function (element) { /// Make one sequence. This equals Repeat(element, 1) /// element /// } Enumerable.Matches = function (input, pattern, flags) { /// Global regex match and send regexp object. /// Ex: Matches((.)z,"0z1z2z") - $[1] => 0,1,2 /// input string /// RegExp or Pattern string /// If pattern is String then can use regexp flags "i" or "m" or "im" /// } Enumerable.Range = function (start, count, step) { /// Generates a sequence of integral numbers within a specified range. /// Ex: Range(1,5) - 1,2,3,4,5 /// The value of the first integer in the sequence. /// The number of sequential integers to generate. /// Step of generate number.(Ex:Range(0,3,5) - 0,5,10) /// } Enumerable.RangeDown = function (start, count, step) { /// Generates a sequence of integral numbers within a specified range. /// Ex: RangeDown(5,5) - 5,4,3,2,1 /// The value of the first integer in the sequence. /// The number of sequential integers to generate. /// Step of generate number.(Ex:RangeDown(0,3,5) - 0,-5,-10) /// } Enumerable.RangeTo = function (start, to, step) { /// Generates a sequence of integral numbers. /// Ex: RangeTo(10,12) - 10,11,12 RangeTo(0,-2) - 0, -1, -2 /// start integer /// to integer /// Step of generate number.(Ex:RangeTo(0,7,3) - 0,3,6) /// } Enumerable.Repeat = function (obj, count) { /// Generates a sequence that contains one repeated value. /// If omit count then generate to infinity. /// Ex: Repeat("foo",3) - "foo","foo","foo" /// The value to be repeated. /// The number of times to repeat the value in the generated sequence. /// } Enumerable.RepeatWithFinalize = function (initializer, finalizer) { /// Lazy Generates one value by initializer's result and do finalize when enumerate end /// value factory. /// execute when finalize. /// } Enumerable.Generate = function (func, count) { /// Generates a sequence that execute func value. /// If omit count then generate to infinity. /// Ex: Generate("Math.random()", 5) - 0.131341,0.95425252,... /// The value of execute func to be repeated. /// The number of times to repeat the value in the generated sequence. /// } Enumerable.ToInfinity = function (start, step) { /// Generates a sequence of integral numbers to infinity. /// Ex: ToInfinity() - 0,1,2,3... /// start integer /// Step of generate number.(Ex:ToInfinity(10,3) - 10,13,16,19,...) /// } Enumerable.ToNegativeInfinity = function (start, step) { /// Generates a sequence of integral numbers to negative infinity. /// Ex: ToNegativeInfinity() - 0,-1,-2,-3... /// start integer /// Step of generate number.(Ex:ToNegativeInfinity(10,3) - 10,7,4,1,...) /// } Enumerable.Unfold = function (seed, func) { /// Applies function and generates a infinity sequence. /// Ex: Unfold(3,"$+10") - 3,13,23,... /// The initial accumulator value. /// An accumulator function to be invoked on each element. /// } Enumerable.prototype = { /* Projection and Filtering Methods */ CascadeBreadthFirst: function (func, resultSelector) { /// Projects each element of sequence and flattens the resulting sequences into one sequence use breadth first search. /// Select child sequence. /// Optional:the second parameter of the function represents the nestlevel of the source sequence. /// }, CascadeDepthFirst: function (func, resultSelector) { /// Projects each element of sequence and flattens the resulting sequences into one sequence use depth first search. /// Select child sequence. /// Optional:the second parameter of the function represents the nestlevel of the source sequence. /// }, Flatten: function () { /// Flatten sequences into one sequence. /// }, Pairwise: function (selector) { /// Projects current and next element of a sequence into a new form. /// A transform function to apply to current and next element. /// }, Scan: function (func_or_seed, func, resultSelector) { /// Applies an accumulator function over a sequence. /// Func is an accumulator function to be invoked on each element. Seed is the initial accumulator value. /// An accumulator function to be invoked on each element. /// A function to transform the final accumulator value into the result value. /// }, Select: function (selector) { /// Projects each element of a sequence into a new form. /// A transform function to apply to each source element; Optional:the second parameter of the function represents the index of the source element. /// }, SelectMany: function (collectionSelector, resultSelector) { /// Projects each element of a sequence and flattens the resulting sequences into one sequence. /// A transform function to apply to each source element; Optional:the second parameter of the function represents the index of the source element. /// Optional:A transform function to apply to each element of the intermediate sequence. /// }, Where: function (predicate) { /// Filters a sequence of values based on a predicate. /// A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element. /// }, OfType: function (type) { /// Filters the elements based on a specified type. /// The type to filter the elements of the sequence on. /// }, Zip: function (second, selector) { /// Merges two sequences by using the specified predicate function. /// The second sequence to merge. /// A function that specifies how to merge the elements from the two sequences. Optional:the third parameter of the function represents the index of the source element. /// }, /* Join Methods */ Join: function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) { /// Correlates the elements of two sequences based on matching keys. /// The sequence to join to the first sequence. /// A function to extract the join key from each element of the first sequence. /// A function to extract the join key from each element of the second sequence. /// A function to create a result element from two matching elements. /// An equality comparer to compare values. /// }, GroupJoin: function (inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) { /// Correlates the elements of two sequences based on equality of keys and groups the results. /// The sequence to join to the first sequence. /// A function to extract the join key from each element of the first sequence. /// A function to extract the join key from each element of the second sequence. /// A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence. /// An equality comparer to compare values. /// }, /* Set Methods */ All: function (predicate) { /// Determines whether all elements of a sequence satisfy a condition. /// A function to test each element for a condition. /// }, Any: function (predicate) { /// Determines whether a sequence contains any elements or any element of a sequence satisfies a condition. /// A function to test each element for a condition. /// }, Concat: function (second) { /// Concatenates two sequences. /// The sequence to concatenate to the first sequence. /// }, Insert: function (index, second) { /// Merge two sequences. /// The index of insert start position. /// The sequence to concatenate to the first sequence. /// }, Alternate: function (value) { /// Insert value to between sequence. /// The value of insert. /// }, // Overload:function(value) // Overload:function(value, compareSelector) Contains: function (value, compareSelector) { /// Determines whether a sequence contains a specified element. /// The value to locate in the sequence. /// An equality comparer to compare values. /// }, DefaultIfEmpty: function (defaultValue) { /// Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty. /// The value to return if the sequence is empty. /// }, Distinct: function (compareSelector) { /// Returns distinct elements from a sequence. /// An equality comparer to compare values. /// }, Except: function (second, compareSelector) { /// Produces the set difference of two sequences. /// An T[] whose Elements that also occur in the first sequence will cause those elements to be removed from the returned sequence. /// An equality comparer to compare values. /// }, Intersect: function (second, compareSelector) { /// Produces the set difference of two sequences. /// An T[] whose distinct elements that also appear in the first sequence will be returned. /// An equality comparer to compare values. /// }, SequenceEqual: function (second, compareSelector) { /// Determines whether two sequences are equal by comparing the elements. /// An T[] to compare to the first sequence. /// An equality comparer to compare values. /// }, Union: function (second, compareSelector) { /// Produces the union of two sequences. /// An T[] whose distinct elements form the second set for the union. /// An equality comparer to compare values. /// }, /* Ordering Methods */ OrderBy: function (keySelector) { /// Sorts the elements of a sequence in ascending order according to a key. /// A function to extract a key from an element. return new OrderedEnumerable(); }, OrderByDescending: function (keySelector) { /// Sorts the elements of a sequence in descending order according to a key. /// A function to extract a key from an element. return new OrderedEnumerable(); }, Reverse: function () { /// Inverts the order of the elements in a sequence. /// }, Shuffle: function () { /// Shuffle sequence. /// }, /* Grouping Methods */ GroupBy: function (keySelector, elementSelector, resultSelector, compareSelector) { /// Groups the elements of a sequence according to a specified key selector function. /// A function to extract the key for each element. /// A function to map each source element to an element in an Grouping<TKey, TElement>. /// A function to create a result value from each group. /// An equality comparer to compare values. /// }, PartitionBy: function (keySelector, elementSelector, resultSelector, compareSelector) { /// Create Group by continuation key. /// A function to extract the key for each element. /// A function to map each source element to an element in an Grouping<TKey, TElement>. /// A function to create a result value from each group. /// An equality comparer to compare values. /// }, BufferWithCount: function (count) { /// Divide by count /// integer /// }, /* Aggregate Methods */ Aggregate: function (func_or_seed, func, resultSelector) { /// Applies an accumulator function over a sequence. /// Func is an accumulator function to be invoked on each element. Seed is the initial accumulator value. /// An accumulator function to be invoked on each element. /// A function to transform the final accumulator value into the result value. /// }, Average: function (selector) { /// Computes the average of a sequence. /// A transform function to apply to each element. /// }, Count: function (predicate) { /// Returns the number of elements in a sequence. /// A function to test each element for a condition. /// }, Max: function (selector) { /// Returns the maximum value in a sequence /// A transform function to apply to each element. /// }, Min: function (selector) { /// Returns the minimum value in a sequence /// A transform function to apply to each element. /// }, MaxBy: function (keySelector) { /// Returns the maximum value in a sequence by keySelector /// A compare selector of element. /// }, MinBy: function (keySelector) { /// Returns the minimum value in a sequence by keySelector /// A compare selector of element. /// }, Sum: function (selector) { /// Computes the sum of a sequence of values. /// A transform function to apply to each element. /// }, /* Paging Methods */ ElementAt: function (index) { /// Returns the element at a specified index in a sequence. /// The zero-based index of the element to retrieve. /// }, ElementAtOrDefault: function (index, defaultValue) { /// Returns the element at a specified index in a sequence or a default value if the index is out of range. /// The zero-based index of the element to retrieve. /// The value if the index is outside the bounds then send. /// }, First: function (predicate) { /// Returns the first element of a sequence. /// A function to test each element for a condition. /// }, FirstOrDefault: function (defaultValue, predicate) { /// Returns the first element of a sequence, or a default value. /// The value if not found then send. /// A function to test each element for a condition. /// }, Last: function (predicate) { /// Returns the last element of a sequence. /// A function to test each element for a condition. /// }, LastOrDefault: function (defaultValue, predicate) { /// Returns the last element of a sequence, or a default value. /// The value if not found then send. /// A function to test each element for a condition. /// }, Single: function (predicate) { /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. /// A function to test each element for a condition. /// }, SingleOrDefault: function (defaultValue, predicate) { /// Returns a single, specific element of a sequence of values, or a default value if no such element is found. /// The value if not found then send. /// A function to test each element for a condition. /// }, Skip: function (count) { /// Bypasses a specified number of elements in a sequence and then returns the remaining elements. /// The number of elements to skip before returning the remaining elements. /// }, SkipWhile: function (predicate) { /// Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. /// A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element. /// }, Take: function (count) { /// Returns a specified number of contiguous elements from the start of a sequence. /// The number of elements to return. /// }, TakeWhile: function (predicate) { /// Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements. /// A function to test each source element for a condition; Optional:the second parameter of the function represents the index of the source element. /// }, TakeExceptLast: function (count) { /// Take a sequence except last count. /// The number of skip count. /// }, TakeFromLast: function (count) { /// Take a sequence from last count. /// The number of take count. /// }, IndexOf: function (item) { /// Returns the zero-based index of the flrst occurrence of a value. /// The zero-based starting index of the search. /// }, LastIndexOf: function (item) { /// Returns the zero-based index of the last occurrence of a value. /// The zero-based starting index of the search. /// }, /* Convert Methods */ ToArray: function () { /// Creates an array from this sequence. /// }, ToLookup: function (keySelector, elementSelector, compareSelector) { /// Creates a Lookup from this sequence. /// A function to extract a key from each element. /// A transform function to produce a result element value from each element. /// An equality comparer to compare values. return new Lookup(); }, ToObject: function (keySelector, elementSelector) { /// Creates a Object from this sequence. /// A function to extract a key from each element. /// A transform function to produce a result element value from each element. /// }, ToDictionary: function (keySelector, elementSelector, compareSelector) { /// Creates a Dictionary from this sequence. /// A function to extract a key from each element. /// A transform function to produce a result element value from each element. /// An equality comparer to compare values. return new Dictionary(); }, // Overload:function() // Overload:function(replacer) // Overload:function(replacer, space) ToJSON: function (replacer, space) { /// Creates a JSON String from sequence, performed only native JSON support browser or included json2.js. /// a replacer. /// indent spaces. /// }, // Overload:function() // Overload:function(separator) // Overload:function(separator,selector) ToString: function (separator, selector) { /// Creates Joined string from this sequence. /// A String. /// A transform function to apply to each source element. /// }, /* Action Methods */ Do: function (action) { /// Performs the specified action on each element of the sequence. /// Optional:the second parameter of the function represents the index of the source element. /// }, ForEach: function (action) { /// Performs the specified action on each element of the sequence. /// [return true;]continue iteration.[return false;]break iteration. Optional:the second parameter of the function represents the index of the source element. /// }, Write: function (separator, selector) { /// Do document.write. /// A String. /// A transform function to apply to each source element. /// }, WriteLine: function (selector) { /// Do document.write + <br />. /// A transform function to apply to each source element. /// }, Force: function () { /// Execute enumerate. /// }, /* Functional Methods */ Let: function (func) { /// Bind the source to the parameter so that it can be used multiple times. /// apply function. /// }, Share: function () { /// Shares cursor of all enumerators to the sequence. /// }, MemoizeAll: function () { /// Creates an enumerable that enumerates the original enumerable only once and caches its results. /// }, /* Error Handling Methods */ Catch: function (handler) { /// catch error and do handler. /// execute if error occured. /// }, Finally: function (finallyAction) { /// do action if enumerate end or disposed or error occured. /// finally execute. /// }, /* For Debug Methods */ Trace: function (message, selector) { /// Trace object use console.log. /// Default is 'Trace:'. /// A transform function to apply to each source element. /// } } // vsdoc-dummy Enumerable.prototype.GetEnumerator = function () { /// Returns an enumerator that iterates through the collection. return new IEnumerator(); } var IEnumerator = function () { } IEnumerator.prototype.Current = function () { /// Gets the element in the collection at the current position of the enumerator. /// } IEnumerator.prototype.MoveNext = function () { /// Advances the enumerator to the next element of the collection. /// } IEnumerator.prototype.Dispose = function () { /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// } var Dictionary = function () { } Dictionary.prototype = { Add: function (key, value) { /// add new pair. if duplicate key then overwrite new value. /// }, Get: function (key) { /// get value. if not find key then return undefined. /// }, Set: function (key, value) { /// set value. if complete set value then return true, not find key then return false. /// }, Contains: function (key) { /// check contains key. /// }, Clear: function () { /// clear dictionary. /// }, Remove: function (key) { /// remove key and value. /// }, Count: function () { /// contains value's count. /// }, ToEnumerable: function () { /// Convert to Enumerable<{Key:, Value:}>. /// } } var Lookup = function () { } Lookup.prototype = { Count: function () { /// contains value's count. /// }, Get: function (key) { /// get grouped enumerable. /// }, Contains: function (key) { /// check contains key. /// }, ToEnumerable: function () { /// Convert to Enumerable<Grouping>. /// } } var Grouping = function () { } Grouping.prototype = new Enumerable(); Grouping.prototype.Key = function () { /// get grouping key. /// } var OrderedEnumerable = function () { } OrderedEnumerable.prototype = new Enumerable(); OrderedEnumerable.prototype.ThenBy = function (keySelector) { /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. /// A function to extract a key from each element. return Enumerable.Empty().OrderBy(); } OrderedEnumerable.prototype.ThenByDescending = function (keySelector) { /// Performs a subsequent ordering of the elements in a sequence in descending order, according to a key. /// A function to extract a key from each element. return Enumerable.Empty().OrderBy(); } return Enumerable; })()