All(array, predicate) : Boolean
Returns true if predicate is true for all items in array or array is empty.
All Parameters
array : []?
predicate : Function
All Examples
numbers.All(n => n % 2 == 0) ? 'All numbers are even' : 'There are some odd numbers';
Any(array, predicate) : Boolean
Returns false if predicate is false for all items in array or array is empty.
Any Parameters
array : []?
predicate : Function
Any Examples
numbers.Any(n => n % 2 == 0) ? 'There are some even numbers' : 'All numbers are odd';
Append(array, item1, …) : []
Adds one or several items to array.
Updates source array in place if possible, otherwise returns new array.
Append Parameters
array : []?
item1 : ?
…? : ?
Append Examples
var ok = [1, 2, 3].Append(4, 5) == [1, 2, 3, 4, 5];
ArraySplit(array, count) : []?
Splits array to several parts of equal lengths (as close as possible).
If count is greater than items count, then empty arrays are generated to get correct number of result arrays.
ArraySplit Parameters
array : []?
count : Integer
ArraySplit Examples
var ok = [1, 2, 3].ArraySplit(2) == [[1, 2], [3]];
Cluster(array, newGroupPredicate) : []?
Splits array to parts using newGroupPredicate(item, index).
Cluster Parameters
array : []?
newGroupPredicate : Function
Cluster Examples
var ok = [1, 2, 3, 4].Cluster(n => n % 2 == 0) == [[1], [2, 3], [4]];
Concat(array1, array2, …) : []
Concatenates arrays to a new array.
Concat Parameters
array1 : []?
array2 : []?
…? : ?
Concat Examples
var ok = [1, 2].Concat([3, 4]) == [1, 2, 3, 4];
Contains(container, item, ignoreCase = false) : Boolean
Checks if array contains item, or dict contains key, or string contains substring, or object contains property.
Contains Parameters
container : ?
Can be array, dict, string or other object.
item : ?
Can be array item, dict key, substring or property name.
ignoreCase : Boolean = false
True to ignore case when matching string element.
Contains Examples
var ok = [1, 2].Contains(1);
var ok = { Key = 'Value' }.Contains('Key');
var ok = 'String'.Contains('ing');
var ok = Duration(1).Contains('Seconds');
Count(array, predicate?) : Integer
Counts all items in array for which predicate(item, index) callback returns true.
If predicate is not specified, then counts all items in array.
Count Parameters
array : []?
predicate? : Function
Count Examples
var ok = [1, 2].Count() == 2;
var ok = [1, 2, 3, 4].Count(n => n % 2 == 0) == 2;
Distinct(array, itemSelector?) : []?
Returns new array without duplicate values.
Distinct Parameters
array : []?
itemSelector? : Function
Distinct Examples
var ok = [1, 2, 3, 3, 1].Distinct() == [1, 2, 3];
var ok = [{ A = 1, B = 2 }, { A = 1, B = 3 }].Distinct(o => o.A) == [{ A = 1, B = 2 }];
Filter(array, predicate) : []?
Returns new array that includes only items for which predicate(item, index) returns true.
Filter Parameters
array : []?
predicate : Function
Filter Examples
var ok = [1, 2, 3, 2, 1].Filter(n => n % 2 == 0) == [2, 2];
FindIndex(array, predicate) : Integer
Finds index of an item in array by predicate(item, index).
Returns 1-based index, or 0 if not found.
FindIndex Parameters
array : []?
predicate : Function
FindIndex Examples
var ok = [1, 2, 3, 4].FindIndex(n => n % 2 == 0) == 2;
First(array, predicate?, defaultValue?)
Returns the first item for which predicate(item, index) returns true.
If predicate is not specified, then returns the first item of array.
If no item is found, then defaultValue or null is returned.
First Parameters
array : []?
predicate? : Function
defaultValue? : ?
First Examples
var ok = [3, 4, 1, 2].First(n => n % 2 == 0) == 4;
var ok = [3, 4, 1, 2].First() == 3;
var ok = [1, 2, 3, 4].First(n => n > 5, 'NO') == 'NO';
var ok = [].First(missing, 'NO') == 'NO';
Flatten(array, subSequenceSelector?) : []?
Transforms each item of array with subSequenceSelector(item, index) callback and concatenates all sub-sequences to one array.
Flatten Parameters
array : []?
subSequenceSelector? : Function
Should return sub-sequence array.
Can be true to treat each item as array and perform deep flattening.
Flatten Examples
var ok = [{ A = 1, B = [1, 2] }, { B = [3, 4] }].Flatten(i => i.B) == [1, 2, 3, 4];
var ok = [[1, 2, [3, 4]], 5, [6, 7, [8, 9], 0]].Flatten(true) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
ForEach(array, action, stopOnFalse = false) : Integer
Performs action(item, index) callback for each item in the specified array and returns items count.
ForEach Parameters
array : []?
action : Function
stopOnFalse : Boolean = false
If true, then the loop stops when action(item, index) returns false (the result of ForEach in this case is the number of iterated items excluding the one that stopped the loop).
ForEach Examples
var ok = [1, 2, 3, 4].ForEach(i => i.Log()) == 4;
var ok = [1, 2, 3, 4].ForEach(i => i.Log() < 3, true) == 2;
GroupBy(array, keySelector, elementSelector?) : []?
Groups items by specified criteria and returns array of groups.
GroupBy Parameters
array : []?
keySelector : Function
keySelector(value, index) returns key to group items by.
elementSelector? : Function
GroupBy Examples
var ok = [1, 2, 3, 4].GroupBy(i => i % 2) == [[1, 3], [2, 4]];
var ok = [1, 2, 3, 4].GroupBy(i => i % 2).First().Key == 1;
In(item, container) : Boolean
Checks if item presents in array, or key presents in dict, or substring in string, or property in object.
In Parameters
item : ?
Can be array item, dict key, substring or property name.
container : ?
Can be array, dict, string or other object.
In Examples
var ok = (2).In([1, 2]);
var ok = 'Key'.In({ Key = 'Value' });
var ok = 'ing'.In('String');
var ok = 'Seconds'.In(Duration(1));
IndexOf(array, item, ignoreCase = false) : Integer
Finds index of an item in array, or substring in string.
Returns 1-based index, or 0 if not found.
IndexOf Parameters
array : []?
Can be array or string.
item : ?
ignoreCase : Boolean = false
True to ignore case when matching strings.
IndexOf Examples
var ok = [1, 2, 1, 2].IndexOf(2) == 2;
var ok = 'ababab'.IndexOf('aba') == 1;
Insert(array, index, item) : []
Inserts item into array at specified index, or inserts substring into string.
Insert Parameters
array : []
index : Integer
item : ?
Insert Examples
var ok = [1, 2].Insert(2, 3) == [1, 3, 2];
var ok = [1, 2].Insert(3, 3) == [1, 2, 3];
Intersect(array1, …) : []
Returns intersection of all array arguments.
Intersect Parameters
array1 : []?
…? : ?
Intersect Examples
var ok = [1, 2].Intersect([2, 3]) == [2];
IsArray(value) : Boolean
Checks if specified value is array.
IsArray Parameters
value : ?
IsArray Examples
var ok = [1, 2].IsArray();
IsEmpty(container) : Boolean
Checks if container (array, dict or string) is empty or null.
IsEmpty Parameters
container : ?
IsEmpty Examples
var ok = not [1, 2].IsEmpty();
var ok = [].IsEmpty();
Last(array, predicate?, defaultValue?)
Returns the last item for which predicate(item, index) returns true.
If predicate is not specified, then returns the last item.
If no item is found, then defaultValue or null is returned.
Last Parameters
array : []?
predicate? : Function
defaultValue? : ?
Last Examples
var ok = [1, 2, 4, 3].Last(n => n % 2 == 0) == 4;
var ok = [1, 2, 3, 4].Last() == 4;
var ok = [1, 2, 3, 4].Last(n => n > 5, 'NO') == 'NO';
var ok = [].Last(missing, 'NO') == 'NO';
LastIndexOf(array, item) : Integer
Finds last index of an item in array, or substring in string.
Returns 1-based index, or 0 if not found.
LastIndexOf Parameters
array : []?
item : ?
LastIndexOf Examples
var ok = [1, 2, 1, 2].LastIndexOf(2) == 4;
var ok = 'ababab'.LastIndexOf('aba') == 3;
Map(array, itemSelector, resolve = false) : []?
Transforms each item of array with itemSelector(item, index) callback and returns new mapped array.
Map Parameters
array : []?
itemSelector : Function
resolve : Boolean = false
Returns resolved items after transformation.
Map Examples
var ok = [1, 2].Map(n => n * 2) == [2, 4];
MapAccessible(array, itemSelector) : []?
Transforms each item of array with itemSelector(item, index) callback and filters out all inaccessible items.
MapAccessible Parameters
array : []?
itemSelector : Function
MapAccessible Examples
var ok = [1, 2].MapAccessible(n => n * 2) == [2, 4];
Reduce(array, accumulator, initValue?)
Applies accumulator(previousResult, item, index) callback to each item of array and returns accumulated value.
If initValue was not specified, then previousResult for the 1st item is null.
Reduce Parameters
array : []?
accumulator : Function
initValue? : ?
Reduce Examples
var ok = [1, 2].Reduce((res, n) => res + n * 2, 0) == 6;
Remove(array, index, count = 1) : []
Removes range from array or string.
Remove Parameters
array : []
index : Integer
count : Integer = 1
Remove Examples
var ok = [1, 2, 3, 4].Remove(2, 2) == [1, 4];
var ok = [1, 2, 3, 4].Remove(3) == [1, 2, 4];
Repeat(count, getItem?) : []
Generates array of specified length, using getItem(index) or nextItem() callback.
Repeat Parameters
count : Integer?
getItem? : Function?
Repeat Examples
var ok = Repeat(4, () => 1) == [1, 1, 1, 1];
var ok = Repeat(4, i => i) == [1, 2, 3, 4];
Reverse(array) : []?
Reverses the order of items in array.
Reverse Parameters
array : []?
Reverse Examples
var ok = [1, 2, 3, 4].Reverse() == [4, 3, 2, 1];
Shuffle(array) : []?
Shuffles array items in random order.
Shuffle Parameters
array : []?
Shuffle Examples
var result = [1, 2, 3, 4].Shuffle();
Skip(array, count) : []?
Returns new array without first count items.
Skip Parameters
array : []?
count : Integer
Skip Examples
var ok = [1, 2, 3, 4].Skip(2) == [3, 4];
SkipWhile(array, predicate) : []?
Bypasses items in array as long as predicate(item, index) is true and then returns the remaining items.
SkipWhile Parameters
array : []?
predicate : Function
SkipWhile Examples
var ok = [1, 2, 3, 4, 0].SkipWhile(n => n < 3) == [3, 4, 0];
Sort(array, ascendingFlag1 = true, keySelector1?, …) : []?
Sorts array in ascending or descending order.
Sort Parameters
array : []?
ascendingFlag1 : Boolean = true
keySelector1? : Function
…? : ?
Sort Examples
var ok = [3, 4, 0, 2, 1, 0].Sort() == [0, 0, 1, 2, 3, 4];
var ok = [3, 4, 0, 2, 1, 0].Sort(false) == [4, 3, 2, 1, 0, 0];
var ok = [3, 4, 0, 2, 1, 0].Sort(true, n => n) == [0, 0, 1, 2, 3, 4];
var ok = [{A=1,B=3}, {A=3,B=1}, {A=2,B=2}].Sort(true, o => o.A) == [{A=1,B=3}, {A=2,B=2}, {A=3,B=1}];
var ok = [{A=2,B=2}, {A=1,B=3}, {A=1,B=1}].Sort(true, o => o.A, false, o => o.B) == [{A=1,B=3}, {A=1,B=1}, {A=2,B=2}];
Table(rows, columns?, keyColumns?) : Table?
Creates table from array of arrays of values.
Table Parameters
rows : []?
Array of arrays of values.
columns? : String[]?
Column names to access cell values by name.
keyColumns? : String[]?
Key columns to select rows by key.
Table Examples
var table = Table([['Key1', 1], ['Key2', 2]], ['Key'], ['Key']);
Take(array, count) : []?
Takes first count items from array.
Take Parameters
array : []?
count : Integer
Take Examples
var ok = [1, 2, 3, 4].Take(2) == [1, 2];
TakeWhile(array, predicate) : []?
Takes items from array as long as predicate(item, index) is true.
TakeWhile Parameters
array : []?
predicate : Function
TakeWhile Examples
var ok = [1, 2, 3, 4, 0].TakeWhile(n => n < 3) == [1, 2];
ToArray(value, lazy = false) : []?
Converts string to array of characters, dict to array of pairs, or materializes sequence to indexed array.
ToArray Parameters
value : ?
lazy : Boolean = false
True to enumerate and cache source array items on demand only.
ToArray Examples
var ok = [1, 2].Map(n => n + 1).ToArray() == [2, 3];
var ok = 'abc'.ToArray() == ['a'.(1), 'b'.(1), 'c'.(1)];
ToDict(array, keySelector?, elementSelector?, mergeElementsSelector?) : Dict?
Transforms array to dictionary object using keySelector(item, index) to get keys, elementSelector(item, index) to get values (or item itself if missing selector), and mergeElementsSelector(prev, value) for duplicate keys.
ToDict Parameters
array : []?
keySelector? : Function
(item, index) => key
elementSelector? : Function
(item, index) => value
mergeElementsSelector? : Function
(prev, value) => mergedValue
ToDict Examples
var ok = [1, 2].ToDict(n => n) == { 1: 1, 2: 2 };
var ok = [1, 2].ToDict(n => n, n => n * 2) == { 1: 2, 2: 4 };
var ok = [1, 2, 1].ToDict(n => n, n => n * 2, (p, v) => p + v) == { 1: 4, 2: 4 };