3 Yet Another Linked List
5 There are many doubly-linked list implementations like it, but this
8 For when an array would be too big, and a Map can't be iterated in
12 [![Build Status](https://travis-ci.org/isaacs/yallist.svg?branch=master)](https://travis-ci.org/isaacs/yallist) [![Coverage Status](https://coveralls.io/repos/isaacs/yallist/badge.svg?service=github)](https://coveralls.io/github/isaacs/yallist)
17 var yallist = require('yallist')
18 var myList = yallist.create([1, 2, 3])
21 // of course pop() and shift() are there, too
22 console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']
23 myList.forEach(function (k) {
24 // walk the list head to tail
26 myList.forEachReverse(function (k, index, list) {
27 // walk the list tail to head
29 var myDoubledList = myList.map(function (k) {
32 // now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']
33 // mapReverse is also a thing
34 var myDoubledListReverse = myList.mapReverse(function (k) {
36 }) // ['foofoo', 6, 4, 2, 'barbar']
38 var reduced = myList.reduce(function (set, entry) {
42 console.log(reduced) // 'startfoo123bar'
47 The whole API is considered "public".
49 Functions with the same name as an Array method work more or less the
52 There's reverse versions of most things because that's the point.
56 Default export, the class that holds and manages a list.
58 Call it with either a forEach-able (like an array) or a set of
59 arguments, to initialize the list.
61 The Array-ish methods all act like you'd expect. No magic length,
62 though, so if you change that it won't automatically prune or add
65 ### Yallist.create(..)
67 Alias for Yallist function. Some people like factories.
71 The first node in the list
75 The last node in the list
79 The number of nodes in the list. (Change this at your peril. It is
80 not magic like Array length.)
82 #### yallist.toArray()
84 Convert the list to an array.
86 #### yallist.forEach(fn, [thisp])
88 Call a function on each item in the list.
90 #### yallist.forEachReverse(fn, [thisp])
92 Call a function on each item in the list, in reverse order.
96 Get the data at position `n` in the list. If you use this a lot,
97 probably better off just using an Array.
99 #### yallist.getReverse(n)
101 Get the data at position `n`, counting from the tail.
103 #### yallist.map(fn, thisp)
105 Create a new Yallist with the result of calling the function on each
108 #### yallist.mapReverse(fn, thisp)
110 Same as `map`, but in reverse.
114 Get the data from the list tail, and remove the tail from the list.
116 #### yallist.push(item, ...)
118 Insert one or more items to the tail of the list.
120 #### yallist.reduce(fn, initialValue)
124 #### yallist.reduceReverse
126 Like Array.reduce, but in reverse.
130 Reverse the list in place.
134 Get the data from the list head, and remove the head from the list.
136 #### yallist.slice([from], [to])
138 Just like Array.slice, but returns a new Yallist.
140 #### yallist.sliceReverse([from], [to])
142 Just like yallist.slice, but the result is returned in reverse.
144 #### yallist.toArray()
146 Create an array representation of the list.
148 #### yallist.toArrayReverse()
150 Create a reversed array representation of the list.
152 #### yallist.unshift(item, ...)
154 Insert one or more items to the head of the list.
156 #### yallist.unshiftNode(node)
158 Move a Node object to the front of the list. (That is, pull it out of
159 wherever it lives, and make it the new head.)
161 If the node belongs to a different list, then that list will remove it
164 #### yallist.pushNode(node)
166 Move a Node object to the end of the list. (That is, pull it out of
167 wherever it lives, and make it the new tail.)
169 If the node belongs to a list already, then that list will remove it
172 #### yallist.removeNode(node)
174 Remove a node from the list, preserving referential integrity of head
175 and tail and other nodes.
177 Will throw an error if you try to have a list remove a node that
178 doesn't belong to it.
182 The class that holds the data and is actually the list.
184 Call with `var n = new Node(value, previousNode, nextNode)`
186 Note that if you do direct operations on Nodes themselves, it's very
187 easy to get into weird states where the list is broken. Be careful :)
191 The next node in the list.
195 The previous node in the list.
199 The data the node contains.
203 The list to which this node belongs. (Null if it does not belong to