ScriptCollections support a standard set of methods; you cannot add new methods to a collection instance.
Method Name | Return type | Arguments | Description |
Add | Integer | element | Adds element to the end of the collection, returns element index |
Insert | <none> | index, element | Inserts element into the collection at specified index; if index is beyond the current bounds of the collection, default-valued elements will be inserted up to the point of index. |
RemoveAt | <none> | index |
Removes element at specified index from the collection |
Clear | <none> | <none> | Removes all elements from the collection |
AddRange | <none> | anotherCollection | Adds elements in anotherCollection to current collection |
InsertRange | <none> | index, anotherCollection | Inserts elements in anotherCollection into the current collection at specified index; if index is beyond the current bounds of the collection, default-valued elements will be inserted up to the point of index. |
RemoveRange | <none> | index, count | Removes count elements from the current collection, starting at index |
Push | <none> | element |
Stack-like operation; pushes element into collection at index 0 |
Pop | <varies> | <none> |
Stack-like operation; pops and returns element at index 0 off the collection |
Enqueue | <none> | element |
Queue-like operation; inserts element into head of collection (index 0) |
Dequeue | <varies> | <none> | Queue-like operation; removes and returns last element in collection |
ForEach | <none> | function or CLR delegate |
Applies function or delegate to each item in the collection: var sum = 0; var x = [ 1, 3, 6 ]; x.ForEach( function ( element ) { sum += element; } ); Function takes either one parameter (the element) or two parameters (the element index, and the element); it should return no value. Supported CLR delegate types are System.Action<object> and System.Action<int, object>. Adding or removing elements from the collection during ForEach iteration results in an error. |
Reverse | Collection | <none> | Returns a new collection with elements from the original collection in reverse order; the original collection is unmodified |
Filter | Collection | function or CLR delegate |
Returns a new collection of elements from the original collection that match a filter function or delegate: var x = [ 1, 3, 6 ]; var y = x.Filter( function ( item ) { if( item % 2 == 0 ) { return true; } else { return false; } } ); Function takes either one parameter (the element) or two parameters (the element index, and the element); it must return a boolean value. Supported CLR delegate types areSystem.Func<object, bool> and System.Func<int, object, bool>. Adding or removing elements from the collection during Filter processing results in an error. |
Transform | Collection | function or CLR delegate |
Returns a new collection of elements transformed by a function or delegate from the original collection: var x = [ 1, 3, 6 ]; var y = x.Transform( function ( item ) { return item.ToString(); } ); Function takes either one parameter (the element) or two parameters (the element index, and the element); it must return a value. Supported CLR delegate types are System.Func<object, object> and System.Func<int, object, object>. Adding or removing elements from the collection during Transform processing results in an error. |
Union | Collection | secondCollection, and optional equality function or equality delegate |
Returns a new collection representing the union of elements in the original collection and elements in secondCollection: var x = [1, 3, 5]; var y = [2, 4, 6]; var z = x.Union( y ); Duplicate values are not preserved in the new collection. By default, element equality is determined using the EqualityComparer<object>.Default implementation. A second parameter may be passed to supply custom equality comparison logic; this can either be a function taking one parameter and returning a computed hash value (integer) for that parameter, or a CLR delegate of type System.Func<object, int>. |
Intersect | Collection | secondCollection, and optional equality function or equality delegate |
Returns a new collection representing the intersection of elements in the original collection and elements in secondCollection: var x = [1, 3, 5]; var y = [2, 4, 5]; var z = x.Intersect( y ); Duplicate values are not preserved in the new collection. By default, element equality is determined using the EqualityComparer<object>.Default implementation. A second parameter may be passed to supply custom equality comparison logic; this can either be a function (applied to each candidate element) taking one parameter and returning a computed hash value (integer) for that parameter, or a CLR delegate of type System.Func<object, int>. |
GetRange | Collection | index, count | Returns a new collection of count elements from the original collection, beginning at index. |
TrueForAll | Boolean | function or CLR delegate |
Applies a boolean function or delegate to all elements of the original collection, and returns a single boolean value indicating whether all elements return true for function or delegate: var x = [ 1, 3, 6 ]; var y = x.TrueForAll( function ( item ) { return item % 2 == 0; } ); Function takes either one parameter (the element) or two parameters (the element index, and the element); it must return a boolean value. Supported CLR delegate types are System.Func<object, boolean> and System.Func<int, object, boolean>. Adding or removing elements from the collection during processing results in an error. |
TrueForAny | Boolean | function or CLR delegate |
Applies a boolean function or delegate to all elements of the original collection, and returns a single boolean value indicating whether any element returns true for function or delegate: var x = [ 1, 3, 6 ]; var y = x.TrueForAny( function ( item ) { return item % 2 == 0; } ); Function takes either one parameter (the element) or two parameters (the element index, and the element); it must return a boolean value. Supported CLR delegate types are System.Func<object, boolean> and System.Func<int, object, boolean>. Adding or removing elements from the collection during processing results in an error. |
OrderBy | Collection | function or CLR delegate, and optional comparison function or comparison delegate |
Returns a new collection of elements from the original collection, ordered by ascending key values generated by function or delegate: var x = ['hi', 'bye', 'cya']; var y = x.OrderBy( function(item) { return item[0]; } ); By default, key comparisons are performed using Comparer<object>.Default. A second parameter may be passed to supply custom comparison logic; this can either be a function taking two parameters and returning an integer (1 if parameter1 is greater, -1 if parameter2 is greater, or 0 if equal), or a CLR delegate of type System.Func<object, object, int>. |
Comments
0 comments
Please sign in to leave a comment.