Class: Dictionary

arrgh. Dictionary

new arrgh.Dictionary(eqComparer)

Represents a collection of keys and values.
Name Type Default Description
eqComparer equalityComparer (===) optional An object that tests if two objects are equal.

Extends

Methods

add(key, value)

Adds the specified key and value to the dictionary.
Name Type Description
key * The key of the element to add.
value * The value of the element to add.
Throws:
When a key is already present in the dictionary.

inherited aggregate(seed, accumulator, resultSelector){*}

Determines whether all elements of the collection satisfy a condition.
When a result selector is passed to the function a seed should also be specified.
Name Type Description
seed * optional The initial accumulator value (mandatory if a result selector is specified).
accumulator accumulator An accumulator function to be invoked on each element.
resultSelector selector optional A function to transform the final accumulator value into the result value.
Returns:
Type Description
* - The final accumulator value.

inherited all(predicate){Boolean}

Determines whether all elements of the collection satisfy a condition.
Name Type Description
predicate predicate A function to test each element for a condition.
Returns:
Type Description
Boolean - True if the list is empty or if all elements in the collection satisfy a condition, else false.

inherited any(predicate){Boolean}

Determines whether the collection contains any elements or if any elements satisfy a condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
See:
Returns:
Type Description
Boolean - True if the collection contains any elements or if any elements satisfy a condition, else false.

inherited asEnumerable(){arrgh.Enumerable}

Returns the input typed as Enumerable.
Returns:
Type Description
arrgh.Enumerable - The input collection as Enumerable.

inherited average(selector){Number}

Computes the average of a collection of values.
Values are converted to numerics, but if this fails unexpected averages may occur.
Name Type Description
selector selector optional A function that projects an element into a new form.
Throws:
Throws an error if the collection contains no elements.
Returns:
Type Description
Number - The average of all values in the collection, or NaN.

clear()

Removes all items from the dictionary.

inherited concat(other){arrgh.Enumerable}

Concatenates two collections.
Name Type Description
other other The collection to concatenate to the current collection.
See:
Returns:
Type Description
arrgh.Enumerable - A collection that contains all the elements of both the current and the other collection.

inherited contains(elem, eqComparer){Boolean}

Determines whether a collection contains a specified element, optionally uses a custom equality comparer.
Name Type Default Description
elem * The element to locate in the collection.
eqComparer equals | equalityComparer (===) optional A function or object that tests if two elements are equal.
Returns:
Type Description
Boolean - Returns whether the specified element is contained in the collection.

containsKey(key)

Check whether a key is present in the dictionary.
Name Type Description
key * The key to locate.
Returns:
True if the key is present, otherwise false.

containsValue(value)

Check whether a value is present in the dictionary.
Name Type Description
value * The value to locate.
Returns:
True if the value is present, otherwise false.

inherited count(predicate){Number}

Specifies how many elements the collection has, or how many satisfy a certain condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
Returns:
Type Description
Number - A number that specifies how many elements the collection has, or how many satisfy a certain condition.

inherited defaultIfEmpty(defaultValue){arrgh.Enumerable}

Returns the elements of the specified collection or a collection containing only the default value if the collection is empty.
Name Type Description
defaultValue * The default value to be returned when the collection is empty.
Returns:
Type Description
arrgh.Enumerable - A new collection containing the elements of the specified collection or a new collection containing only the default value if the collection is empty.

inherited distinct(eqComparer){arrgh.Enumerable}

Returns distinct elements from a collection by using the default or a custom equality comparer to compare values.
Name Type Default Description
eqComparer equals | equalityComparer (===) optional A function or object that tests if two elements are equal.
Returns:
Type Description
arrgh.Enumerable - A new collection with unique elements.

inherited elementAt(index){*}

Returns the element at a specified index.
Name Type Description
index Number The index of the element to find.
Throws:
Throws an error if the specified index is outside the bounds of the collection.
Returns:
Type Description
* - The element at the specified index.

inherited elementAtOrDefault(index, defaultValue){*}

Returns the element at a specified index or a default value.
Name Type Description
index Number The index of the element to find.
defaultValue * optional The value that is returned when the specified index is not found.
Returns:
Type Description
* - The element at the specified index or a default value.

inherited except(other, eqComparer){arrgh.Enumerable}

Produces the set difference of two collections.
Name Type Default Description
other arrgh.Enumerable A collection whose elements that also occur in the first sequence will cause those elements to be removed from the returned collection.
eqComparer equals | equalityComparer (===) optional A function or object that tests if two elements are equal.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the set difference of the elements of two collections.

inherited filter(predicate){arrgh.Enumerable}

Filters a collection of values based on a predicate. Each element's index is used in the logic of the predicate function.
Name Type Description
predicate indexPredicate A function to test each element for a condition.
See:
Returns:
Type Description
arrgh.Enumerable - A collection that contains all elements that satisfy the condition.

inherited first(predicate){*}

Returns the first element in a collection, or the first element that satisfies a condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
Throws:
Throws an error if the collection is empty or when no element matches the condition.
Returns:
Type Description
* - Returns the first element of the collection, or the first element that satisfies a condition.

inherited firstOrDefault(predicate, defaultValue){*}

Returns the first element in a collection, or the first element that satisfies a condition.
If the element is not found returns a default value.
Name Type Description
predicate predicate optional A function to test each element for a condition.
defaultValue * optional The value that is returned when the collection is empty or no element matches the condition.
Returns:
Type Description
* - Returns the first element of the collection, or the first element that satisfies a condition, or a specified default value.

inherited forEach(callback)

Performs the specified action on each element of the collection.
Name Type Description
callback forEachCallback The callback that is applied to each element in the enumerable.

get(key){*}

Gets the item at the specified key.
Name Type Description
key * The key of the element which should be retrieved.
Throws:
Throws an error when the key is not present in the dictionary.
Returns:
Type Description
* - Returns the element with the specified key.

inherited getIterator(){arrgh.Iterator}

Returns an iterator that iterates through the collection.
Returns:
Type Description
arrgh.Iterator - Returns an iterator that iterates through the collection.

getKeys(){Array}

Gets all keys in the dictionary.
Returns:
Type Description
Array - An array containing all keys in the dictionary.

getValues(){Array}

Gets all values in the dictionary.
Returns:
Type Description
Array - An array containing all values in the dictionary.

inherited groupBy(keySelector, elementSelector, resultSelector, eqComparer)

Groups the elements of a collection according to a specified key selector.
Name Type Default Description
keySelector keySelector A function that returns the key value from an element.
elementSelector selector optional A function to project an element into a new form.
resultSelector groupByResultSelector optional A function to create a result value from each group.
eqComparer equalityComparer (===) optional An object that tests if two keys are equal.

inherited groupJoin(inner, outerKeySelector, innerKeySelector, resultSelector, eqComparer){arrgh.Enumerable}

Correlates the elements of two collections based on equality of keys and groups the results.
Name Type Default Description
inner arrgh.Enumerable The collection to join with.
outerKeySelector keySelector A function that returns the key value from an element of the outer collection.
innerKeySelector keySelector A function that returns the key value from an element of the inner collection.
resultSelector groupJoinResultSelector A function to create a result value from each group.
eqComparer equalityComparer (===) optional An object that tests if two keys are equal.
Returns:
Type Description
arrgh.Enumerable - A collection that contains elements that are obtained by performing a grouped join on two collections.

inherited indexOf(searchElem, fromIndex){Number}

Finds the first index at which a given element can be found in the collection, or -1 if it is not present.
Name Type Default Description
searchElem * The element to locate in the collection.
fromIndex Number 0 optional The index to start the search at.
Returns:
Type Description
Number - The first index of the element in the array or -1 if not found.

inherited intersect(other, eqComparer){arrgh.Enumerable}

Produces the set intersection of two collections.
Name Type Default Description
other arrgh.Enumerable A collection whose elements that also occur in the first sequence will cause those elements to be included in the returned collection.
eqComparer equals | equalityComparer (===) optional A function or object that tests if two elements are equal.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the set intersection of the elements of two collections.

inherited join(inner, outerKeySelector, innerKeySelector, resultSelector, eqComparer)

Correlates the elements of two collections based on equality of keys.
Name Type Default Description
inner arrgh.Enumerable The collection to join with.
outerKeySelector keySelector A function that returns the key value from an element of the outer collection.
innerKeySelector keySelector A function that returns the key value from an element of the inner collection.
resultSelector joinResultSelector A function to create a result from two matched elements.
eqComparer equalityComparer (===) optional An object that tests if two keys are equal.

inherited last(predicate){*}

Returns the last element in a collection, or the last element that satisfies a condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
Throws:
Throws an error when the collection is empty or when no element matches the condition.
Returns:
Type Description
* - Returns the last element of the collection, or the last element that satisfies a condition.

inherited lastIndexOf(searchElem, fromIndex){Number}

Finds the last index at which a given element can be found in the collection, or -1 if it is not present.
Name Type Default Description
searchElem * The element to locate in the collection.
fromIndex Number 0 optional The index to start the search at.
Returns:
Type Description
Number - The last index of the element in the array or -1 if not found.

inherited lastOrDefault(predicate, defaultValue){*}

Returns the last element in a collection, or the last element that satisfies a condition.
If the element is not found returns a default value.
Name Type Description
predicate predicate optional A function to test each element for a condition.
defaultValue * optional The value that is returned when the collection is empty or no element matches the condition.
Returns:
Type Description
* - Returns the last element of the collection, or the last element that satisfies a condition, or a specified default value.

inherited map(selector){arrgh.Enumerable}

Projects each element of a collection into a new form.
Name Type Description
selector indexSelector A function that projects an element into a new form.
See:
Returns:
Type Description
arrgh.Enumerable - A collection whose elements are the result of invoking the transform function on each element of source.

inherited max(selector){*}

Returns the maximum value in a collection.
Values are converted to numerics. If this fails and the value is NaN then NaN is treated as smaller than anything.
Name Type Description
selector selector optional A function that projects an element into a new form.
Throws:
Throws an error when the collection is empty.
Returns:
Type Description
* - Returns the maximum value in the collection or NaN.

inherited min(selector){*}

Returns the minimum value in a collection.
Values are converted to numerics. If this fails the function returns NaN.
Name Type Description
selector selector optional A function that projects an element into a new form.
Throws:
Throws an error when the collection is empty.
Returns:
Type Description
* - Returns the minimum value in the collection or NaN.

inherited ofType(type){arrgh.Enumerable}

Filters elements based on a specified type (constructor).
Object and null do not evaluate to the same type and neither do undefined and null.
Name Type Description
type * | undefined | null The constructor of a type or undefined or null.
Returns:
Type Description
arrgh.Enumerable - Returns a collection containing only values that are of the specified type.

inherited orderBy(keySelector, compare){arrgh.OrderedEnumerable}

Sorts the elements of a sequence in ascending order according to a key.
Name Type Description
keySelector keySelector A function to extract a key from an element.
compare compare optional A function that tests if an object is smaller than, greater than or equal to another object.
Returns:
Type Description
arrgh.OrderedEnumerable - Returns an ordered enumerable.

inherited orderByDescending(keySelector, compare){arrgh.OrderedEnumerable}

Sorts the elements of a sequence in descending order according to a key.
Name Type Description
keySelector keySelector A function to extract a key from an element.
compare compare optional A function that tests if an object is smaller than, greater than or equal to another object.
Returns:
Type Description
arrgh.OrderedEnumerable - Returns an ordered enumerable.

remove(key){Boolean}

Removes the value with the specified key from the dictionary.
Name Type Description
key * The key of the element to remove.
Returns:
Type Description
Boolean - True if the key was successfully removed and false when the key was not found.
Reverses the order of the elements in a collection.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the original collection in reversed order.

inherited select(selector){arrgh.Enumerable}

Projects each element of a collection into a new form.
Name Type Description
selector indexSelector A function that projects an element into a new form.
See:
Returns:
Type Description
arrgh.Enumerable - A collection whose elements are the result of invoking the transform function on each element of source.

inherited selectMany(collectionSelector, resultSelector){arrgh.Enumerable}

Projects each element of a collection to an Enumerable and flattens the resulting collections into one collection.
Name Type Description
collectionSelector collectionSelector A function that projects an element into a new form.
resultSelector selectManyResultSelector optional A function that creates a result value from each element in the intermediate collection.
Returns:
Type Description
arrgh.Enumerable - A collection whose elements are the result of invoking the one-to-many transform function on each element of the input collection.

inherited sequenceEquals(other, eqComparer){Boolean}

Determines whether two collections are equal by comparing the elements, optionally using a custom equality comparer for their type.
Name Type Default Description
other arrgh.Enumerable Another collection to compare with.
eqComparer equalityComparer (===) optional An object that tests if two objects are equal.
Returns:
Type Description
Boolean - True if all elements in both collections match, otherwise false.

set(key, value){*}

Sets the item at the specified key.
Name Type Description
key * The key of the element to overwrite.
value * The value to set.
Throws:
Throws an error when the key is not present in the dictionary.
Returns:
Type Description
* - Returns the element with the specified key.

inherited single(predicate){*}

Returns the only element in a collection, or the only element that satisfies a condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
Throws:
Throws an error when the collection is empty or when no element matches the condition or when the collection (or predicate) returns more than a single element.
Returns:
Type Description
* - Returns the only element of the collection, or the only element that satisfies a condition.

inherited singleOrDefault(predicate, defaultValue){*}

Returns the only element in a collection, or the only element that satisfies a condition.
If the element is not found returns a default value.
Name Type Description
predicate predicate optional A function to test each element for a condition.
defaultValue * optional The value that is returned when the collection is empty or no element matches the condition.
Throws:
Throws an error when the collection (or predicate) returns more than a single element.
Returns:
Type Description
* - Returns the only element of the collection, or the only element that satisfies a condition, or a specified default value.
Bypasses a specified number of elements in a collection and then returns the remaining elements.
Name Type Description
count Number The number of elements to skip.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the elements that occur after the specified index.

inherited skipWhile(predicate){arrgh.Enumerable}

Bypasses elements in a collection as long as a specified condition is true and then returns the remaining elements.
Name Type Description
predicate indexPredicate A function to test whether to skip the element.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the elements starting at the first element in the linear series that does not pass the test specified by predicate.

inherited some(predicate){Boolean}

Determines whether the collection contains any elements or if any elements satisfy a condition.
Name Type Description
predicate predicate optional A function to test each element for a condition.
See:
Returns:
Type Description
Boolean - True if the collection contains any elements or if any elements satisfy a condition, else false.

inherited sum(selector){Number}

Computes the sum of a collection of values.
If values are not numerics the result may be NaN or something unexpected (e.g. "2" + 2 will results 22).
Name Type Description
selector selector optional A function that projects an element into a new form.
Throws:
Throws an error if the collection contains no elements.
Returns:
Type Description
Number - The sum of all values in the collection, or NaN.
Returns a specified number of elements from the start of a collection.
Name Type Description
count Number The number of elements to take.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the elements that occur before the specified index.

inherited takeWhile(predicate){arrgh.Enumerable}

Returns elements from a collection as long as a specified condition is true.
Name Type Description
predicate indexPredicate A function to test whether to take the element.
Returns:
Type Description
arrgh.Enumerable - A collection that contains the elements that occur before the element at which the test no longer passes.

inherited toArray(){Array}

Converts the collection to a JavaScript array.
Returns:
Type Description
Array - Returns a JavaScript array.

inherited toDictionary(keySelector, elementSelector, eqComparer){arrgh.Dictionary}

Converts the collection to a dictionary.
Name Type Default Description
keySelector keySelector A function that returns the key value from an element of the inner collection.
elementSelector selector optional A function that projects an element into a new form.
eqComparer equalityComparer (===) optional An object that tests if two keys are equal.
Returns:
Type Description
arrgh.Dictionary - Returns a dictionary containing the keys and elements that are selected from the input collection.

inherited toList(){arrgh.List}

Converts the collection to a list.
Returns:
Type Description
arrgh.List - Returns a List containing all the elements from the input collection.

inherited toLookup(keySelector, elementSelector, eqComparer){arrgh.Lookup}

Converts the collection to a collection of keys each mapped to one or more values.
Name Type Default Description
keySelector keySelector A function that returns the key value from an element of the inner collection.
elementSelector selector optional A function that projects an element into a new form.
eqComparer equalityComparer (===) optional An object that tests if two keys are equal.
Returns:
Type Description
arrgh.Lookup - Returns a collection of keys mapped to one or more values.

tryGet(key){tryResult}

Removes the value with the specified key from the dictionary.
Name Type Description
key * The key at which the item should be retrieved.
Returns:
Type Description
tryResult - A result specifying whether the key was found and, if yes, also contains the value for the key.

inherited union(other, eqComparer){arrgh.Enumerable}

Produces the set union of two collections by using the default or a custom equality comparer to compare values.
Name Type Default Description
other arrgh.Enumerable The other collection to union with.
eqComparer equalityComparer (===) optional An object that tests if two elements are equal.
Returns:
Type Description
arrgh.Enumerable - A collection that contains distinct element from the two input collections.

inherited unionAll(other){arrgh.Enumerable}

Concatenates two collections.
Name Type Description
other other The collection to concatenate to the current collection.
See:
Returns:
Type Description
arrgh.Enumerable - A collection that contains all the elements of both the current and the other collection.

inherited where(predicate){arrgh.Enumerable}

Filters a collection of values based on a predicate. Each element's index is used in the logic of the predicate function.
Name Type Description
predicate indexPredicate A function to test each element for a condition.
See:
Returns:
Type Description
arrgh.Enumerable - A collection that contains all elements that satisfy the condition.

inherited zip(other, resultSelector){arrgh.Enumerable}

Applies a specified function to the corresponding elements of two collections, producing a collection of the results.
Name Type Description
other arrgh.Enumerable The collection to merge with.
resultSelector zipResultSelector A function that creates a result value from two elements.
Returns:
Type Description
arrgh.Enumerable - A collection that contains merged elements of two input collections.