LinkedList Class
Doubly linked list for storing items. Supports iteration via LinkedListIterator (returned by this.iterator()) or Y.each(). Also supports all the other operations defined in gallery-funcprog.
Direct indexing into the list is not supported, as a reminder that it is an expensive operation. Instead, use find() with a function that checks the index.
Constructor
LinkedList
-
[list]
Parameters:
-
[list]
Mixed optionalany scalar or iterable list
Item Index
Methods
append
-
value
Parameters:
-
value
Mixedvalue to append
Returns:
clear
()
Clear the list.
each
-
f
-
c
Executes the supplied function on each item in the list. The function receives the value, the index, and the list itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
every
-
f
-
c
Executes the supplied function on each item in the list. Iteration stops if the supplied function does not return a truthy value. The function receives the value, the index, and the list itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
filter
-
f
-
c
Executes the supplied function on each item in the list. Returns a new list containing the items for which the supplied function returned a truthy value. The function receives the value, the index, and the object itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
find
-
f
-
c
Executes the supplied function on each item in the list, searching for the first item that matches the supplied function. The function receives the value, the index, and the object itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
head
()
LinkedListItem
Returns:
indexOf
-
needle
Parameters:
-
needle
Mixedthe item to search for
Returns:
insertAfter
-
item
-
value
Parameters:
-
item
LinkedListItemexisting item
-
value
Mixedvalue to insert
Returns:
insertBefore
-
value
-
item
Parameters:
-
value
Mixedvalue to insert
-
item
LinkedListItemexisting item
Returns:
isEmpty
()
Boolean
Returns:
lastIndexOf
-
needle
Parameters:
-
needle
Mixedthe item to search for
Returns:
map
-
f
-
c
Executes the supplied function on each item in the list and returns a new list with the results. The function receives the value, the index, and the object itself as parameters (in that order).
Parameters:
-
f
Stringthe function to invoke
-
c
Objectoptional context object
Returns:
partition
-
f
-
c
Partitions an list into two new list, one with the items for which the supplied function returns true, and one with the items for which the function returns false. The function receives the value, the index, and the object itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
prepend
-
value
Parameters:
-
value
Mixedvalue to prepend
Returns:
reduce
-
init
-
f
-
c
Executes the supplied function on each item in the list, folding the list into a single value. The function receives the value returned by the previous iteration (or the initial value if this is the first iteration), the value being iterated, the index, and the list itself as parameters (in that order). The function must return the updated value.
Parameters:
-
init
Mixedthe initial value
-
f
Stringthe function to invoke
-
c
Objectoptional context object
Returns:
reject
-
f
-
c
Executes the supplied function on each item in the list. Returns a new list containing the items for which the supplied function returned a falsey value. The function receives the value, the index, and the object itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object
Returns:
remove
()
Remove the item from the list.
reverse
()
Reverses the items in place.
size
()
Number
Warning: This requires traversing the list! Use isEmpty() whenever possible.
Returns:
some
-
f
-
c
Executes the supplied function on each item in the list. Iteration stops if the supplied function returns a truthy value. The function receives the value, the index, and the list itself as parameters (in that order).
Parameters:
-
f
Functionthe function to execute on each item
-
c
Objectoptional context object