Specialized list implementation for instances of type Edge.
Type Details
- yfiles module
- algorithms
- yfiles-umd modules
- All layout modules, view-layout-bridge
- Legacy UMD name
- yfiles.algorithms.EdgeList
See Also
Constructors
Creates a list that is initialized with the edges provided by the given array of edges.
Creates a list that is initialized with the edges provided by the given IEdgeCursor object.
Creates a list that is initialized with those edges from the given EdgeCursor object for which the given data provider returns true
upon calling its getBool method.
Parameters
A map of options to pass to the method.
- ec - IEdgeCursor
- An edge cursor providing edges that should be added to this list.
- predicate - IDataProvider
- A data provider that acts as a inclusion predicate for each edge accessible by the given edge cursor.
Creates a list that is initialized with a single edge provided.
Properties
Gets the first element of this list.
Whether this collection is read-only.
Implements
Gets the last element of this list.
Gets the number of elements in this list.
Overrides
Methods
Appends all elements provided by the given collection to this list.
Adds all elements provided by the given collection to this list at the specified position.
Remarks
Parameters
A map of options to pass to the method.
- index - number
- index at which the first element of the specified collection is placed
- c - ICollection<Object>
- the collection that contains the elements to be added
Returns
- ↪boolean
true
if this list was changed,false
otherwise
Throws
- Exception({ name: 'IndexOutOfRangeError' })
- if the index is out of range, that is, negative or larger than the size of this list
Defined in
Adds a formerly removed ListCell object at the head of this list.
Adds a formerly removed ListCell object at the tail of this list.
Creates a wrapped enumerable that has one or several elements appended to it.
Remarks
items
any special if they are array-like or enumerable-like.Parameters
A map of options to pass to the method.
- items - any
- The item(s) to prepend to the enumeration
Returns
- ↪IEnumerable<any>
- A new live view over the original enumerable that has each of the
items
appended to it.
Examples
const list = List.fromArray([1, 2, 3, 4])
const appendedEnumerable = list.append(5, 6)
console.log(appendedEnumerable.toArray()) // yields [1,2,3,4,5,6]
// show live updates
list.add(4.5)
console.log(appendedEnumerable.toArray()) // yields [1,2,3,4,4.5,5,6]
See Also
Overrides
Creates a wrapped enumerable that has one or several elements appended to it.
Remarks
items
any special if they are array-like or enumerable-like.Parameters
A map of options to pass to the method.
- items - Edge
- The item(s) to prepend to the enumeration
Returns
- ↪IEnumerable<Edge>
- A new live view over the original enumerable that has each of the
items
appended to it.
Examples
const list = List.fromArray([1, 2, 3, 4])
const appendedEnumerable = list.append(5, 6)
console.log(appendedEnumerable.toArray()) // yields [1,2,3,4,5,6]
// show live updates
list.add(4.5)
console.log(appendedEnumerable.toArray()) // yields [1,2,3,4,4.5,5,6]
See Also
Defined in
Returns the element at the given index
in this enumerable.
Parameters
A map of options to pass to the method.
- index - number
- The index of the element to return. Supports relative indexing from the end of the enumerable when passed a negative index. In other words, if a negative number is used, the returned element will be found by counting back from the end of the enumerable.
Returns
- ↪any
- The element at the given
index
, orundefined
if the index is not within the range of this enumerable.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable.at(0)) // yields 1
console.log(enumerable.at(-1)) // yields 4
console.log(enumerable.at(5)) // yields undefined
Overrides
Removes all elements from this list.
Implements
Concatenates this enumerable with the given other elements
in a new dynamic IEnumerable<T>.
Remarks
Parameters
A map of options to pass to the method.
- elements - Object
- Rest arguments to be appended. In case the elements are enumerable-like, too, they will be will be enumerated after the others have been enumerated. But this can also be simple objects of type
T
in which case they will be appended to the enumerable just like with append
Returns
- ↪IEnumerable<any>
- A dynamic composite enumerable.
Examples
const enumerable1 = IEnumerable.from([1, 2])
const enumerable2 = IEnumerable.from([3, 4])
console.log(enumerable1.concat(enumerable2).toArray()) // yields [1,2,3,4]
// single values can be used, too
console.log(enumerable1.concat(3, 4).toArray()) // yields [1,2,3,4]
// arrays are flattened
console.log(enumerable1.concat([5, 6], [7, 8]).toArray()) // now contains [1,2,5,6,7,8]
// works with arrays and array-like collections, too
console.log(enumerable1.concat([3, 4]).toArray()) // yields [1,2,3,4]
See Also
Overrides
Copies the elements of this collection to an array, starting at the specified array index.
Returns a cursor for this list.
Remarks
Defined in
Creates a wrapped enumerable that yields each element only once.
Remarks
Parameters
A map of options to pass to the method.
- keySelector - function(any):Object
- The optional function that determines the key to determine distinctness of the elements. If omitted, the element itself is used.
- thisArg - Object
- The optional object to use for
this
in thekeySelector
function
.
Returns
- ↪IEnumerable<any>
- A new live view over the original enumerable that yields each element with a given key at most once.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 3, 4])
const result = enumerable.distinct()
console.log(result.toArray()) // yields [1,2,3,4]
See Also
Overrides
Returns an edge cursor for this edge list.
Returns
- ↪IEdgeCursor
- An edge cursor granting access to the edges within this list.
Returns the i-th element of this list.
Preconditions
i
is a valid index, i.e.,i >= 0 && i < size()
.
Parameters
A map of options to pass to the method.
- i - number
- The index of the element to return.
Returns
- ↪any
- The element at the given
index
.
Throws
- Exception({ name: 'ArgumentError' })
- If the
index
is not within the range of this enumerable.
See Also
Overrides
Determines whether every element of the enumerable matches the given predicate
.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the element matches a condition.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪boolean
true
if all elements of the enumerable match the givenpredicate
,false
otherwise.
Throws
- Exception({ name: 'ArgumentError' })
predicate
isnull
.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable.every((item) => item < 5)) // true
console.log(enumerable.every((item) => item < 4)) // false
Overrides
filter
(predicate: function(any, number, IEnumerable<any>):boolean, thisArg?: Object) : IEnumerable<any>Returns a dynamic IEnumerable<T> of the elements of this enumerable which match the given predicate
.
Remarks
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the given element should be included in the resulting enumerable.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪IEnumerable<any>
- A dynamic enumerable of the elements which match the given
predicate
.
Examples
const enumerable = IEnumerable.from([10, 2, 30, 4, 5, 6])
const result = enumerable.filter((item) => item < 5)
console.log(result.toArray()) // yields [2,4]
Overrides
Returns the first element of this enumerable, the first element of the enumerable that matches a given predicate
if specified, or null
if there is no such element.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The first element of this enumerable, its first element that matches a given predicate, or
null
if there is no such element.
Examples
const enumerable = IEnumerable.from([10, 2, 3, 9, 5, 6])
console.log(enumerable.find((item) => item < 5)) // yields 2
// no matches with the given predicate
console.log(enumerable.find((item) => item < 2)) // yields null
Overrides
Returns the ListCell where object o
is stored.
Searches the enumerable for the first item for which predicate
returns true
and returns its index.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if an item matches the search conditions.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪number
- The index of the first item for which
predicate
returnstrue
or -1 if there is no such item in the enumerable.
Overrides
Returns the last element of this enumerable, the last element of the enumerable that matches a given predicate
if specified, or null
if there is no such element.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The last element of this enumerable, its last element that matches a given predicate, or
null
if there is no such element.
Examples
const enumerable = IEnumerable.from([10, 2, 3, 9, 5, 6])
console.log(enumerable.findLast((item) => item < 5)) // yields 3
// no matches with the given predicate
console.log(enumerable.findLast((item) => item < 2)) // yields null
Overrides
findLastIndex
(predicate: function(any, number, IEnumerable<any>):boolean, thisArg?: Object) : numberSearches the enumerable for the last item for which predicate
returns true
and returns its index.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if an item matches the search conditions.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪number
- The index of the last item for which
predicate
returnstrue
or -1 if there is no such item in the enumerable.
Overrides
Returns the first element of this enumerable or the first element of this enumerable that matches a given predicate
, if specified.
Remarks
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The first matching element of this enumerable.
Throws
- Exception({ name: 'InvalidOperationError' })
- If this enumerable does not contain a matching element.
Examples
const enumerable = IEnumerable.from([10, 2, 3, 9, 5, 6])
console.log(enumerable.first((item) => item < 5)) // yields 2
// no matches with the given predicate
console.log(enumerable.first((item) => item < 2)) // throws exception
See Also
Overrides
Returns the first element of this enumerable, the first element of this enumerable that matches a given predicate
, if specified, or null
if there is no such element.
Remarks
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The first element of this enumerable, its first element that matches a given predicate, or
null
if there is no such element.
Examples
const enumerable = IEnumerable.from([10, 2, 3, 9, 5, 6])
console.log(enumerable.firstOrDefault((item) => item < 5)) // yields 2
// no matches with the given predicate
console.log(enumerable.firstOrDefault((item) => item < 2)) // yields null
See Also
Deprecation warning
Use IEnumerable.find or IEnumerable.at instead.Overrides
flatMap
<TResult>(selector: function(any, number, IEnumerable<any>):IEnumerable<TResult>, thisArg?: Object) : IEnumerable<TResult>Returns a flattened dynamic IEnumerable<T> of this enumerable using the given selector
function which returns an enumerable for each element of this enumerable.
Remarks
Type Parameters
- TResult
Parameters
A map of options to pass to the method.
- selector - function(any, number, IEnumerable<any>):IEnumerable<TResult>
- A function which returns an enumerable for each element of this enumerable.
Signature Details
function(element: any, index: number, source: IEnumerable<any>) : IEnumerable<TResult>
The selector to use for the IEnumerable<T>.A function which returns a result of type IEnumerable<T> for eachelement
.Parameters
- element - any
- The current element create a result for.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- IEnumerable<TResult>
- A result of type
of TResult
created from theelement
.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪IEnumerable<TResult>
- A flattened dynamic enumerable of the enumerables provided for each element of this enumerable.
Examples
const enumerable = IEnumerable.from([1, 2, 3])
const result = enumerable.flatMap((item) =>
IEnumerable.from([item, item * 2])
)
console.log(result.toArray()) // yields [1,2,2,4,3,6]
const enumerable = IEnumerable.from<number>([1, 2, 3])
const result = enumerable.flatMap((item) =>
IEnumerable.from<number>([item, item * 2])
)
console.log(result.toArray()) // yields [1,2,2,4,3,6]
Overrides
Iterates this enumerable and invokes the given function for each element with the element, its index, and this enumerable as arguments.
Parameters
A map of options to pass to the method.
- action - function(any, number, IEnumerable<any>):void
- The function to call for each element.
Signature Details
function(element: any, index: number, source: IEnumerable<any>)
An action to execute for each element of an IEnumerable<T>.Parameters
- element - any
- The current element.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4])
enumerable.forEach((item) => console.log(item)) // 1 2 3 4
// accessing the index
enumerable.forEach((item, index) =>
console.log(`Item #${index} is ${item}`)
)
Overrides
Gets the cell at the given index.
Returns an enumerator for this collection.
Returns
- ↪IEnumerator<Edge>
- An IEnumerator<T> that can be used to iterate through this collection.
Overrides
groupBy
<TKey,TResult>(keySelector: function(any, number, IEnumerable<any>):TKey, resultCreator?: function(TKey, IEnumerable<any>, number):TResult, thisArg?: Object) : IEnumerable<TResult>Groups the elements in the enumerable according to the equality of a key.
Remarks
keySelector
will be used to retrieve a key. All elements with the same key will be provided to the optional resultCreator
function that receives both the key, and an IEnumerable<T> of the elements that match that key to create a resulting object that will be yielded by this enumerable. Note that the resulting enumerable does not necessarily preserve the order of the (first) appearance of their elements in the original sequence. The elements of each group passed to the resultCreator
are in the order of their original appearance.Type Parameters
- TKey
- The type of the key elements.
- TResult
- The type of the created elements.
Parameters
A map of options to pass to the method.
- keySelector - function(any, number, IEnumerable<any>):TKey
- A function which selects from each element the key.
Signature Details
function(element: any, index: number, source: IEnumerable<any>) : TKey
A function which creates a key for the givenelement
.Parameters
- element - any
- The element to get the key for.
- index - number
- The index of the element in the underlying
. - source - IEnumerable<any>
- The underlying
Returns
- TKey
- resultCreator - function(TKey, IEnumerable<any>, number):TResult
- An optional function which transforms each group of elements and their common key into a resulting object. If omitted, the default implementation will create arrays of length 2 where the first element is the key and the second element is an IEnumerable<TSource> of the elements with the corresponding key.
Signature Details
function(key: TKey, group: IEnumerable<any>, index: number) : TResult
A function which transforms a group of elements and their common key into a resulting object.Parameters
- key - TKey
- The key of the provided group.
- group - IEnumerable<any>
- The group of elements with the given key.
- index - number
- The index of the group.
Returns
- TResult
- A resulting object for the given group with the given key.
- thisArg - Object
- The optional value to use as
this
when executing thekeySelector
andresultCreator
.
Returns
- ↪IEnumerable<TResult>
- An enumeration of groups of the original enumerable.
Examples
Overrides
Returns a hash code for this object.
Remarks
The hash code is a numeric value that can be used to treat this object as a key in a hash table or similar data structure.
Two objects that are considered equal must have the same hash code. However, the reverse does not hold and two objects having the same hash code don't have to be equal. Ideally, the hash code should be roughly uniformly-distributed to prevent hash tables from performing poorly. Calculating the hash code is also a potentially frequent operation and should therefore be fast.
Returns
- ↪number
- the hash code for this object
Defined in
Determines whether the given value is part of this enumerable.
Parameters
A map of options to pass to the method.
- value - any
- The value to search for.
Returns
- ↪boolean
true
if this enumerable contains the given value,false
otherwise.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable.includes(2)) // true
console.log(enumerable.includes(5)) // false
Overrides
Determines whether the given value is part of this enumerable.
Parameters
A map of options to pass to the method.
- value - Edge
- The value to search for.
Returns
- ↪boolean
true
if this enumerable contains the given value,false
otherwise.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable.includes(2)) // true
console.log(enumerable.includes(5)) // false
Defined in
The index of the given item in the enumerable.
Parameters
A map of options to pass to the method.
- item - any
- The item to search for.
- fromIndex - number
Returns
- ↪number
- The index of the given item in the enumerable.
-1
if the item is not in the enumerable.
Overrides
The index of the given item in the enumerable.
Parameters
A map of options to pass to the method.
- item - Edge
- The item to search for.
- fromIndex - number
Returns
- ↪number
- The index of the given item in the enumerable.
-1
if the item is not in the enumerable.
Defined in
Inserts the given element
into this list at the given index
.
Inserts the given object into this list with respect to a given reference list cell.
Remarks
The (newly created) list cell that stores the object is inserted right after the reference list cell refCell
.
If refCell == null
, the given object is inserted at the head of the list.
Preconditions
refCell
must be part of this list.
Parameters
A map of options to pass to the method.
Returns
- ↪ListCell
- The newly created ListCell object that stores object
o
.
Defined in
Inserts the given object into this list with respect to a given reference list cell.
Remarks
The (newly created) list cell that stores the object is inserted right before the reference list cell refCell
.
If refCell == null
, the given object is appended to the list.
Preconditions
refCell
must be part of this list.
Parameters
A map of options to pass to the method.
Returns
- ↪ListCell
- The newly created ListCell object that stores object
o
.
Defined in
Inserts a formerly removed ListCell object into this list with respect to a given reference list cell.
Remarks
The ListCell object is inserted right after the reference list cell refCell
.
Attention: If the ListCell object is still part of any list, then that list will be corrupted afterwards.
Preconditions
refCell
must be part of this list.
Parameters
A map of options to pass to the method.
- cellToInsert - ListCell
- A list cell which is not part of any list.
- refCell - ListCell
- The list cell used to reference the position.
Defined in
Inserts a formerly removed ListCell object into this list with respect to a given reference list cell.
Remarks
The ListCell object is inserted right before the reference list cell refCell
.
Attention: If the ListCell object is still part of any list, then that list will be corrupted afterwards.
Preconditions
refCell
must be part of this list.
Parameters
A map of options to pass to the method.
- cellToInsert - ListCell
- A list cell which is not part of any list.
- refCell - ListCell
- The list cell used to reference the position.
Defined in
Checks whether this list contains elements.
Defined in
Returns the last element of this enumerable or the last element of this enumerable that matches a given predicate
, if specified.
Remarks
Array.findLast"
method. Consider using that method instead.Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The last element of this enumerable.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the enumerable is empty.
Examples
const enumerable1 = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable1.last()) // yields 4
// if the enumerable is empty then an exception will be thrown
const enumerable2 = IEnumerable.from([])
console.log(enumerable2.last()) // throws exception
See Also
Overrides
Returns the last element of this enumerable, the last element of this enumerable that matches a given predicate
, if specified, or null
if there is no such element.
Remarks
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A predicate function which returns
true
if the given element should be returned.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪any
- The last element of the enumerable or
null
.
Examples
const enumerable1 = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable1.lastOrDefault()) // yields 4
// if the enumerable is empty then null will be returned
const enumerable2 = IEnumerable.from([])
console.log(enumerable2.lastOrDefault()) // yields null
See Also
Deprecation warning
Use IEnumerable.findLast or IEnumerable.at instead.Overrides
map
<TResult>(selector: function(any, number, IEnumerable<any>):TResult, thisArg?: Object) : IEnumerable<TResult>Returns a dynamic IEnumerable<T> of this enumerable using the given selector
function which returns a new object for each element of this enumerable.
Remarks
Type Parameters
- TResult
- The type of the mapped elements.
Parameters
A map of options to pass to the method.
- selector - function(any, number, IEnumerable<any>):TResult
- A function which converts each element into a new element of the type
TResult
.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : TResult
The selector to use for the IEnumerable<T>.A function which returns a result of typeTResult
for eachelement
.Parameters
- element - any
- The current element create a result for.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- TResult
- A result of type
TResult
created from theelement
.
- thisArg - Object
- The optional value to use as
this
when executing theselector
.
Returns
- ↪IEnumerable<TResult>
- A dynamic enumerable of the results of the provided function.
Examples
const enumerable = IEnumerable.from([1, 2, 3])
const result = enumerable.map((item) => item * 2)
console.log(result.toArray()) // yields [2, 4, 6]
// with index
const result2 = enumerable.map((item, index) => item * index)
console.log(result2.toArray()) // yields [0, 2, 6]
// with index and enumerable
const result3 = enumerable.map(
(item, index, enumerable) =>
`Item no ${index} of ${enumerable.size} is ${item}`
)
console.log(result3.toArray())
// ["Item no 0 of 3 is 1","Item no 1 of 3 is 2","Item no 2 of 3 is 3"]
const enumerable = IEnumerable.from([1, 2, 3])
const result = enumerable.map((item) => item * 2)
console.log(result.toArray()) // yields [2, 4, 6]
// with index
const result2 = enumerable.map((item, index) => item * index)
console.log(result2.toArray()) // yields [0, 2, 6]
// with index and enumerable
const result3 = enumerable.map(
(item, index, enumerable) =>
`Item no ${index} of ${enumerable!.size} is ${item}`
)
console.log(result3.toArray())
// ["Item no 0 of 3 is 1","Item no 1 of 3 is 2","Item no 2 of 3 is 3"]
Overrides
Converts this untyped enumerable into an enumerable with the given type.
Remarks
Type Parameters
- TResult
Returns
- ↪IEnumerable<TResult>
- A typed enumerable.
Overrides
orderBy
<TKey>(keySelector?: function(any):TKey, comparer?: function(TKey, TKey):number, thisArg?: Object) : IEnumerable<any>Yields an ordered enumerable of the elements given a key selection function and optional comparison function and creates a ordered view of the enumerable.
Remarks
Type Parameters
- TKey
Parameters
A map of options to pass to the method.
- keySelector - function(any):TKey
- The function that determines the key for sorting the elements. If omitted, the element itself is used.
Signature Details
function(element: any) : TKey
A function which creates a key for the givenelement
.Parameters
- element - any
- The element to get the key for.
Returns
- TKey
- The key for the element.
- comparer - function(TKey, TKey):number
- A function with the signature
function(key1, key2):Number
which is used for the sort operation to compare the key elements in the enumerable. May be omitted.Signature Details
function(value1: TKey, value2: TKey) : number
Compares the given values.Parameters
- value1 - TKey
- The first value to compare.
- value2 - TKey
- The second value to compare.
Returns
- number
- A value less than 0 if value 1 is smaller than value2, 0 if both values are equal, greater than 0 otherwise.
- thisArg - Object
Returns
- ↪IEnumerable<any>
- An enumeration of groups of the original enumerable.
Examples
const enumerable = IEnumerable.from([
{ type: 'name-6', rank: 8 },
{ type: 'name-23', rank: 4 },
{ type: 'name-3', rank: 5 }
])
// order by the elements' rank, without a comparer function
const sortedEnumerable1 = enumerable.orderBy((entry) => entry.rank)
console.log(sortedEnumerable1.toArray())
// [{ "type": "name-23", "rank": 4 }, { "type": "name-3", "rank": 5 }, { "type": "name-6", "rank": 8 }]
// order by the elements' type using numeric collation to get a more "natural" order, with a comparer function
const collator = new Intl.Collator(undefined, {
numeric: true,
sensitivity: 'base'
})
const sortedEnumerable2 = enumerable.orderBy(
(entry) => entry.type,
collator.compare
)
console.log(sortedEnumerable2.toArray())
// [{ "type": "name-3", "rank": 5 }, { "type": "name-6", "rank": 8 },{ "type": "name-23", "rank": 4 }]
Overrides
orderByDescending
<TKey>(keySelector?: function(any):TKey, comparer?: function(TKey, TKey):number, thisArg?: Object) : IEnumerable<any>Yields an ordered enumerable of the elements given a key selection function and optional comparison function and creates a ordered view of the enumerable where the elements are yielded in descending order.
Remarks
Type Parameters
- TKey
Parameters
A map of options to pass to the method.
- keySelector - function(any):TKey
- The function that determines the key for sorting the elements. If omitted, the element itself is used.
Signature Details
function(element: any) : TKey
A function which creates a key for the givenelement
.Parameters
- element - any
- The element to get the key for.
Returns
- TKey
- The key for the element.
- comparer - function(TKey, TKey):number
- A function with the signature
function(key1, key2):Number
which is used for the sort operation to compare the key elements in the enumerable. May be omitted.Signature Details
function(value1: TKey, value2: TKey) : number
Compares the given values.Parameters
- value1 - TKey
- The first value to compare.
- value2 - TKey
- The second value to compare.
Returns
- number
- A value less than 0 if value 1 is smaller than value2, 0 if both values are equal, greater than 0 otherwise.
- thisArg - Object
Returns
- ↪IEnumerable<any>
- An enumeration of groups of the original enumerable.
Examples
const enumerable = IEnumerable.from([
{ type: 'A' },
{ type: 'B' },
{ type: 'C' },
{ type: 'D' }
])
// order by the elements' types, without a comparer function
const sortedEnumerable1 = enumerable.orderByDescending(
(entry) => entry.type
)
console.log(sortedEnumerable1.toArray())
// [{ "type": "D" }, { "type": "C" }, { "type": "B" }, { "type": "A" }]
Overrides
Equivalent to firstObject.
Defined in
Removes and returns the last value in this list.
Remarks
Array.pop()
function and returns undefined
if the list is empty.Returns
- ↪any
- The removed value.
undefined
if the list was empty.
Overrides
Creates a wrapped enumerable that has on or several elements prepended to it.
Parameters
A map of options to pass to the method.
- items - any
- The item(s) to prepend to the enumeration
Returns
- ↪IEnumerable<any>
- A new live view over the original enumerable that has
items
prepended to it.
Examples
const enumerable1 = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable1.prepend(0).toArray()) // yields [0,1,2,3,4]
// more than one value can be used too
const enumerable2 = IEnumerable.from([3, 4, 5, 6])
console.log(enumerable2.prepend(1, 2).toArray()) // yields [1,2,3,4,5,6]
See Also
Overrides
Creates a wrapped enumerable that has on or several elements prepended to it.
Parameters
A map of options to pass to the method.
- items - Edge
- The item(s) to prepend to the enumeration
Returns
- ↪IEnumerable<Edge>
- A new live view over the original enumerable that has
items
prepended to it.
Examples
const enumerable1 = IEnumerable.from([1, 2, 3, 4])
console.log(enumerable1.prepend(0).toArray()) // yields [0,1,2,3,4]
// more than one value can be used too
const enumerable2 = IEnumerable.from([3, 4, 5, 6])
console.log(enumerable2.prepend(1, 2).toArray()) // yields [1,2,3,4,5,6]
See Also
Defined in
Adds one or more elements to this list and returns the new length.
Remarks
Array.push()
function.Parameters
A map of options to pass to the method.
- values - any
- The values to append to the list.
Returns
- ↪number
- The new length of the list.
Overrides
reduce
<TAccumulate>(accumulator: function(TAccumulate, any, number, IEnumerable<any>):TAccumulate, initialValue: TAccumulate) : TAccumulateApplies the accumulator
function to this elements of this enumerable.
Type Parameters
- TAccumulate
- The type of the accumulated value.
Parameters
A map of options to pass to the method.
- accumulator - function(TAccumulate, any, number, IEnumerable<any>):TAccumulate
- A function which "adds" (accumulates) a value depending on the element and index to the initial value and returns the result.
Signature Details
function(total: TAccumulate, element: any, index: number, source: IEnumerable<any>) : TAccumulate
The accumulator to use for the IEnumerable<T>.A function which returns a result of typeTAccumulate
as an accumulation oftotal
andelement
.Parameters
- total - TAccumulate
- The previously returned value of the function.
- element - any
- The current element to accumulate.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- TAccumulate
- A result of type
TAccumulate
created from theelement
.
- initialValue - TAccumulate
- The initial value for the accumulator. Omit/use the reduce overload if you don't want to specify an initial value.
Returns
- ↪TAccumulate
- The result of the accumulation.
Examples
See Also
Overrides
Applies the accumulator
function to this elements of this enumerable.
Parameters
A map of options to pass to the method.
- accumulator - function(any, any, number, IEnumerable<any>):any
- A function which "adds" (accumulates) a value depending on the element and index to the initial value and returns the result.
Signature Details
function(total: any, element: any, index: number, source: IEnumerable<any>) : any
The accumulator to use for the IEnumerable<T>.A function which returns a result of typeTAccumulate
as an accumulation oftotal
andelement
.Parameters
- total - any
- The previously returned value of the function.
- element - any
- The current element to accumulate.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- any
- A result of type
TAccumulate
created from theelement
.
Returns
- ↪any
- The result of the accumulation.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4, 5])
const result = enumerable.reduce(
(accumulator, currentValue) => accumulator + currentValue
)
console.log(result) // expected output: 15
See Also
Overrides
reduceRight
<TAccumulate>(accumulator: function(TAccumulate, any, number, IEnumerable<any>):TAccumulate, initialValue: TAccumulate) : TAccumulateApplies the accumulator
function to this elements of this enumerable in reverse order.
Type Parameters
- TAccumulate
- The type of the accumulated value.
Parameters
A map of options to pass to the method.
- accumulator - function(TAccumulate, any, number, IEnumerable<any>):TAccumulate
- A function which "adds" (accumulates) a value depending on the element and index to the seed value and returns the result.
Signature Details
function(total: TAccumulate, element: any, index: number, source: IEnumerable<any>) : TAccumulate
The accumulator to use for the IEnumerable<T>.A function which returns a result of typeTAccumulate
as an accumulation oftotal
andelement
.Parameters
- total - TAccumulate
- The previously returned value of the function.
- element - any
- The current element to accumulate.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- TAccumulate
- A result of type
TAccumulate
created from theelement
.
- initialValue - TAccumulate
- The initial value for the accumulator. Omit/use the reduceRight overload if you don't want to specify an initial value.
Returns
- ↪TAccumulate
- The final value of the accumulation.
Examples
See Also
Overrides
Applies the accumulator
function to this elements of this enumerable in reverse order.
Parameters
A map of options to pass to the method.
- accumulator - function(any, any, number, IEnumerable<any>):any
- A function which "adds" (accumulates) a value depending on the element and index to the seed value and returns the result.
Signature Details
function(total: any, element: any, index: number, source: IEnumerable<any>) : any
The accumulator to use for the IEnumerable<T>.A function which returns a result of typeTAccumulate
as an accumulation oftotal
andelement
.Parameters
- total - any
- The previously returned value of the function.
- element - any
- The current element to accumulate.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- any
- A result of type
TAccumulate
created from theelement
.
Returns
- ↪any
- The result of the accumulation.
Examples
const enumerable = IEnumerable.from([
[0, 1],
[2, 3],
[4, 5]
])
const result = enumerable.reduceRight((accumulator, currentValue) =>
accumulator.concat(currentValue)
)
console.log(result) // yields [4,5,2,3,0,1]
See Also
Overrides
Removes the given collection of objects from this list.
Removes the element at the position specified by the given index
.
Parameters
A map of options to pass to the method.
- index - number
- The index that specifies the element to remove.
Implements
Retains only those elements in this list which are contained in the given collection.
Complexity
This operation has running time O(max(m, n)), were m and n are the sizes of this list and the given collection, respectively.
Returns
- ↪boolean
- Whether there have been elements removed.
Defined in
Reverses the sequence of elements in this list.
Defined in
Removes and returns the first value in this list.
Remarks
Array.shift()
function and returns undefined
if the list is empty.Returns
- ↪any
- The removed value.
undefined
if the list was empty.
Overrides
Creates a wrapped view of an enumerable which skips the given amount of elements.
Parameters
A map of options to pass to the method.
- amount - number
- The number of elements to skip at the beginning.
Returns
- ↪IEnumerable<any>
- A new live view over the original enumerable that skips
amount
elements.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4, 5, 6, 7])
const result = enumerable.skip(3)
console.log(result.toArray()) // yields [4,5,6,7]
See Also
Overrides
skipWhile
(predicate: function(any, number, IEnumerable<any>):boolean, thisArg?: Object) : IEnumerable<any>Creates a wrapped view of an enumerable which skips a number of elements at the beginning while the given predicate yields true
.
Remarks
predicate
yields true
for the elements of the original enumerable, the elements are skipped. The new enumeration will start with the first element for which the predicate yields false
. All subsequent elements will be yielded.Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- The predicate function that determines what elements should be skipped. While the predicate yields
true
for the provided item, the element will not be yielded.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in the predicatefunction
.
Returns
- ↪IEnumerable<any>
- A new live view over the original enumerable that discards elements at the beginnging of the original enumeration while the predicate yields
true
.
Examples
const enumerable = IEnumerable.from([
'a',
'b',
'c',
'd',
'a',
'b',
'c',
'd'
])
const result = enumerable.skipWhile(
(element) => element.charCodeAt(0) < 'c'.charCodeAt(0)
)
console.log(result.toArray()) // yields ["c", "d", "a", "b", "c", "d"]
See Also
Overrides
Determines whether this enumerable contains any elements matching the given predicate
.
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A function which returns
true
if the element matches a condition.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪boolean
- Whether this enumerable contains any elements matching the given
predicate
.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4, 5, 6, 7])
const result = enumerable.some((item) => item % 2 === 0)
console.log(result) // true
Overrides
Sorts the elements in this list according to the given comparator.
Remarks
Complexity
O(size() * log(size()))
Defined in
Sorts the elements in this list into ascending order, according to their natural ordering.
Remarks
All elements must implement the IComparable interface. Furthermore, all elements in this list must be mutually comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException for any elements e1
and e2
in this list).
NOTE: The elements will be assigned to different list cells by this method.
Complexity
O(size() * log(size()))
Defined in
Transfers the contents of the given list to the end of this list.
Remarks
The given list will be empty after this operation.
Note that this operation transfers the list cells of the given list to this list. No new list cells are created by this operation.
Complexity
O(1)
Defined in
Calculates the sum of the elements of this enumerable.
Parameters
A map of options to pass to the method.
- selector - function(any, number, IEnumerable<any>):number
- A function which returns a numeric value for the given element.
Signature Details
function(element: any, index: number, source: IEnumerable<any>) : number
The selector to use for the IEnumerable<T>.A function which returns a result of typeTResult
for eachelement
.Parameters
- element - any
- The current element create a result for.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- number
- A result of type
TResult
created from theelement
.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪number
- The sum of the elements of the enumerable.
Examples
const enumerable = IEnumerable.from([
{ type: 'A', amount: 3 },
{ type: 'B', amount: 2 },
{ type: 'C', amount: 2 },
{ type: 'D', amount: 5 }
])
const result = enumerable.sum((element) => element.amount)
console.log(result) // yields 12
Overrides
Creates a dynamic view of this enumerable with the given number of elements taken from the start or end of this enumerable.
Parameters
A map of options to pass to the method.
- count - number
- The number of elements in the created enumerable. If the number is positive, the elements are taken from the beginning, otherwise, the elements are taken from the end.
Returns
- ↪IEnumerable<any>
- A dynamic iew of this enumerable with the given number of elements.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4, 5, 6, 7])
// positive parameter means taking elements from the beginning of the enumerable
console.log(enumerable.take(2).toArray()) // yields [1,2]
// negative parameter means taking elements from the end of the enumerable
console.log(enumerable.take(-2).toArray()) // yields [6,7]
See Also
Overrides
takeWhile
(predicate: function(any, number, IEnumerable<any>):boolean, thisArg?: Object) : IEnumerable<any>Returns a dynamic IEnumerable<T> that contains the elements from this enumerable as long as the given predicate
is true
.
Remarks
Parameters
A map of options to pass to the method.
- predicate - function(any, number, IEnumerable<any>):boolean
- A function which returns
true
as long as the elements should be added to the returned enumerable.Signature Details
function(element: any, index: number, source: IEnumerable<any>) : boolean
The predicate to use for IEnumerable<T>.Parameters
- element - any
- The current element to test.
- index - number
- The element's index in the
- source - IEnumerable<any>
- The enumerable this function is called upon.
Returns
- boolean
true
if the item matches the condition.
- thisArg - Object
- The optional object to use for
this
in thefunction
.
Returns
- ↪IEnumerable<any>
- A dynamic enumerable that is a subset of the original enumerable.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 30, 4, 5])
const result = enumerable.takeWhile((item) => item < 5)
console.log(result.toArray()) // yields [1,2,3]
Overrides
Returns an array representation of this list.
Returns an edge array containing all elements of this list in the canonical order.
Creates a List<T> with the values of this enumerable.
Returns an dynamic enumerable which contains the elements of this enumerable in reverse order.
Remarks
Returns
- ↪IEnumerable<any>
- A dynamic enumerable which contains the elements of the original enumerable in reverse order.
Examples
const enumerable = IEnumerable.from([1, 2, 3, 4, 5])
const result = enumerable.toReversed()
console.log(result.toArray()) // yields [5,4,3,2,1]
Overrides
Returns a string representation of this list.
Defined in
Adds one or more elements to the beginning of this list and returns the new length.
Remarks
Array.unshift()
function.Parameters
A map of options to pass to the method.
- values - any
- The values to prepend to this list. The first argument will become the new first element in the list
Returns
- ↪number
- The new length of the list.